1

我想要的是在用户提交表单时添加一个对象路由值(ajax.beginform)

根据用户在 ConfirmDone 函数中选择的内容,我想添加一个整数(SaveOption)

但我真的不知道该怎么做。

调用了 confirmdone 函数,但就是这样,我的控制器操作没有被调用。我可能需要退货?

一些代码:表格的开头

@using (Ajax.BeginForm("CreateFunctiebeschrijvingPartial", "Functiebeschrijving", new     AjaxOptions { UpdateTargetId = "Functiebeschrijving", OnBegin = "return ConfirmDone()", OnSuccess = "handleSuccess" }, new {@id = frmID}))
{

确认完成功能

function ConfirmDone() {
    if (confirm("This form saves default as Concept, would you like to save it as completed? 1 = Completed, 2 = Concept")) {
        //option 1: save as completed
        $('#frmID').attr("SaveOption", 1);                        
    }
    else {
        //Option 2: save as concept
    }
}

我的控制器动作的开始

//
// POST: /FunctieBeschrijving/CreateFunctiebeschrijvingPartial
[HttpPost]
public ActionResult CreateFunctiebeschrijvingPartial(NieuweFunctiebeschrijvingViewModel nfvm, int SaveOption)
{

当我不使用确认功能时,一切都按原样发布!

4

1 回答 1

1
function addDataToUrl(url, name, value){
    var sep = url.indexOf('?') === -1 ? '?' : '&';
    return url + sep + name + '=' + value;   
}

function ConfirmDone() {
    var form = document.getElementById('frmID');
    if (confirm("This form saves default as Concept, would you like to save it as completed? 1 = Completed, 2 = Concept")) {
        //option 1: save as completed
        form.setAttribute('action', 
        addDataToUrl(form.getAttribute('action'), 'SaveOption', '1'));                   
    }
    else {
        // Option 2: save as concept
    }
}
于 2013-07-17T10:14:02.003 回答