MVC4多按钮forms不起作用JQM

我在MVC4中面对我的JQuery移动APP上的一个奇怪的问题:

我有一个表格,里面有几个这样的texbox

@using Models @model Models.DataModel.Pagina_Details @{ Layout = "~/Views/Shared/_Layout.cshtml"; } @using (Html.BeginForm("Pagina_Details", "Home", FormMethod.Post, new { id = "PaginaDetailsForm" })) { if (Request.QueryString["Command"] != null) { Session["Command"] = Request.QueryString["Command"]; } else { Response.Redirect("Index"); } 

Pagina's

@Html.HiddenFor(model => model.ID) @Html.LabelFor(model => model.Name, "Naam *", new { @class = "lbl"}) @Html.TextBoxFor(model => model.Name, new { required = "required" }) @Html.LabelFor(model => model.Description, "Omschrijving *", new { @class = "lbl"}) @Html.TextArea("Description", new { required = "required", rows="10", cols="80"}) @Html.LabelFor(model => model.MetaDescription, "Meta description", new { @class = "lbl" }) @Html.TextBoxFor(model => model.MetaDescription) @Html.LabelFor(model => model.MetaKeywords, "Meta keywords", new { @class = "lbl" }) @Html.TextBoxFor(model => model.MetaKeywords) @Html.LabelFor(model => model.Active, "Actief", new { @class = "lbl" }) @Html.CheckBoxFor(model => model.Active) @if (Session["Command"] == "Insert" || Request.QueryString["Command"] == "Insert") { } @if (Session["Command"] != "Insert" && Request.QueryString["Command"] != "Insert") { }
}

在我的ActionResult(控制器)我有param命令,并在交换机中使用它来做它的问题在桌面浏览器上运行良好,我可以看到命令传递给ActionResult一切正常,因为它应该但由于某种原因,当我在手机上使用Phonegap尝试同样的事情时,Command值将始终为null

我尝试了什么:AttributeUsage 如何处理ASP.NET MVC框架中的多个提交按钮? 根本没有结果。

我也为2个按钮尝试了不同的ActionResults,根本没有结果。

我失去了有人知道一些提示或有任何想法如何我可以解决这个问题。 你的时间和帮助。

这可能不是你想要的,但为什么不使用按钮作为javascript函数,可以在提交之前更改表单的操作。 我认为这是保持逻辑清洁和简单修复的好方法。 由于你使用phonegap javascript不应该是一个问题。 祝好运!

  

希望这可以帮助! -DREW

试试这个 :

如果要使用多个提交按钮,则必须使用传递FormCollection Form参数来执行此操作

如果要使用多个提交按钮,首先更改您的输入按钮名称不能相同,因此请将提交按钮代码更改为:

 @if (Session["Command"] != "Insert" && Request.QueryString["Command"] != "Insert") {   } 

现在On Home控制器发布Pagina_Details动作的事件写成:

 [HttpPost] public ActionResult Pagina_Details(FormCollection Form,ModelClassName ModelClassObject) { if(Form["CommandBtn1"]!=null) { /// Write code for Opslaan (Edit Code) } if(Form["CommandBtn2"]!=null) { /// Write code for Verwijderen (Delete Code) } return View(); } 

希望它的作品。