在Ajax.BeginForm的“确认”对话框中添加对象routedValue

Add object routedValue in Confirmation dialog of a Ajax.BeginForm

本文关键字:对话框 添加 对象 routedValue 确认 Ajax BeginForm      更新时间:2023-09-26

我想要的是在用户提交表单(axax.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)
{

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

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
    }
}