C# 表单中的MVC4多按钮不工作JQM

C# 表单中的MVC4多按钮不工作JQM,c#,asp.net-mvc,asp.net-mvc-4,jquery-mobile,C#,Asp.net Mvc,Asp.net Mvc 4,Jquery Mobile,我在MVC4中的JQuery移动应用程序上遇到了一个奇怪的问题: 我有一张表格,上面有几个像这样的盒子 @using Models @model Models.DataModel.Pagina_Details @{ Layout = "~/Views/Shared/_Layout.cshtml"; } @using (Html.BeginForm("Pagina_Details", "Home", FormMethod.Post, new { id = "PaginaDet

我在MVC4中的JQuery移动应用程序上遇到了一个奇怪的问题:

我有一张表格,上面有几个像这样的盒子

@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");
}
<div class="ui-corner-all custom-corners ui-shadow">
  <div class="ui-bar ui-bar-a">
    <h3>Pagina's</h3>
  </div>
<div class="ui-body ui-body-a">
 <input type="hidden" id="Command" />
  @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")
{
    <button type="submit" name="Command" data-role="button" data-icon="plus">Toevoegen</button>
}       
@if (Session["Command"] != "Insert" && Request.QueryString["Command"] != "Insert")
{
    <button type="submit" id="Edit" name="Command" value="Opslaan" data-role="button" data-icon="edit">Opslaan</button>
    <button type="submit" id="Verwijderen" name="Command" value="Verwijderen" data-role="button" data-icon="delete">Verwijderen</button>
}

</div>

</div>

}
使用模型 @model.DataModel.Pagina_详细信息 @{ Layout=“~/Views/Shared/_Layout.cshtml”; } @使用(Html.BeginForm(“Pagina_Details”,“Home”,FormMethod.Post,new{id=“PaginaDetailsForm”})) { if(Request.QueryString[“Command”]!=null) { 会话[“命令”]=请求。查询字符串[“命令”]; } 其他的 { 响应。重定向(“索引”); } 帕吉纳氏 @Html.HiddenFor(model=>model.ID) @LabelFor(model=>model.Name,“Naam*”,new{@class=“lbl”}) @Html.TextBoxFor(model=>model.Name,新的{required=“required”}) @LabelFor(model=>model.Description,“Omschrijving*”,新的{@class=“lbl”}) @TextArea(“Description”,new{required=“required”,rows=“10”,cols=“80”}) @LabelFor(model=>model.MetaDescription,“MetaDescription”,新的{@class=“lbl”}) @Html.TextBoxFor(model=>model.MetaDescription) @LabelFor(model=>model.MetaKeywords,“MetaKeywords”,new{@class=“lbl”}) @Html.TextBoxFor(model=>model.MetaKeywords) @LabelFor(model=>model.Active,“Actief”,new{@class=“lbl”}) @CheckBoxFor(model=>model.Active) @如果(会话[“命令”]=“插入”| |请求.查询字符串[“命令”]=“插入”) { 托沃根 } @if(会话[“命令”]!=“插入”&&Request.QueryString[“命令”]!=“插入”) { 奥普斯兰 维尔维德伦 } } 在我的ActionResult(Controller)中,我有param命令 在开关中使用它做一些事情问题是 在桌面浏览器上,它运行良好,我可以看到命令正在传递给ActionResult,一切正常,但由于某种原因,当我 使用Phonegap在我的手机上尝试相同的操作命令值将始终为空

我尝试的是: 归属 没有结果

我还尝试了两个按钮的不同操作结果 没有结果

我迷路了。是否有人知道一些提示或有任何想法我可以如何解决这个问题。
感谢您的时间和帮助。

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

<script type="text/javascript">
document.getElementById("edit").onclick = function() {
 a=document.getElementsByTagName("form")[0];
a.action ="URL for Edit";
a.submit();
 }
document.getElementById("Verwijderen").onclick = function() {
 a=document.getElementsByTagName("form")[0];
a.action ="URL for Verwijderen";
a.submit();
 }

</script>

document.getElementById(“编辑”).onclick=function(){
a=document.getElementsByTagName(“表单”)[0];
a、 action=“用于编辑的URL”;
a、 提交();
}
document.getElementById(“Verwijderen”).onclick=function(){
a=document.getElementsByTagName(“表单”)[0];
a、 action=“Verwijderen的URL”;
a、 提交();
}
希望这有帮助! -Drew

试试这个:

如果您想使用multiple submit按钮,那么必须使用pass FormCollection Form参数来执行如下post操作

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

@if (Session["Command"] != "Insert" && Request.QueryString["Command"] != "Insert")
{
    <button type="submit" id="Edit" name="CommandBtn1" value="Opslaan" data-role="button" data-icon="edit">Opslaan</button>
    <button type="submit" id="Verwijderen" name="CommandBtn2" value="Verwijderen" data-role="button" data-icon="delete">Verwijderen</button>
}

希望它能起作用。

不,这不是我想要的,因为它的动作(ActionResult)都是一样的,但谢谢你的想法:)该死的,哈哈,我得到的一切。我的问题是,是否所有的逻辑都必须发生在一个动作结果中。如果你把它分成3个,你可以用2个变量把所有的工作都传递给1。这只是一个选择,但我认为打破逻辑有助于组织。嘿,我复制了这个答案。第二个更容易。当我使用诸如public ActionResult(Model D,String Command){if(Command==“A”){//Do Something}之类的传递变量时,它在我的桌面PC上工作,但在我的移动设备上不工作,仅此而已?我不知道为什么它在我的移动平台(谷歌浏览器)上不起作用:(
[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();
}