在Ajax.BeginForm的Confirmation对话框中添加对象routedValue

时间:2013-07-17 09:55:31

标签: javascript asp.net-mvc-4 confirmation ajax.beginform

我想要的是在用户提交表单时添加对象路由值(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)
{

当我不使用确认功能时,所有内容都应该发布!

1 个答案:

答案 0 :(得分: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
    }
}