MVC4 Multibuttons在形式上不工作JQM [英] MVC4 Multibuttons in form not working JQM
问题描述
林在MVC4我的jQuery Mobile的APP面对一个奇怪的问题:
Im Facing a weird problem on my JQuery mobile APP in MVC4:
我有这样一对夫妇texboxes形式
I have a form with a couple of texboxes like this
@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>
}
在我的ActionResult(控制器)我有param命令
和使用,在切换到用它做什么的问题是
在桌面浏览器效果很好,我可以看到该命令被传递到的ActionResult,一切工作正常,因为它应该是,但由于某种原因,当我
试试我的手机上同样的事情与PhoneGap的命令值将始终为空
in my ActionResult (Controller) i have the param Command and use that in a switch to do something with it the issue is on the desktop browser it works well and i can see the command is passing to the ActionResult and everything works fine as it should be but for some reason when i try the same thing on my Mobile phone with Phonegap the Command value will always be null
什么我tryed:
AttributeUsage
<一href=\"http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework\">How你处理多个提交按钮在ASP.NET MVC框架?
没有结果的。
What i tryed: AttributeUsage How do you handle multiple submit buttons in ASP.NET MVC Framework? no result at all.
我也尝试过不同的ActionResults的2个按钮
没有结果的。
also i tried different ActionResults for the 2 buttons no result at all.
IM确实有人知道一些提示或有任何想法如何,我可以解决这个问题。
TY您的时间和帮助。
im lost does someone knows some tips or have any ideas how i can fix this. ty for your time and help.
推荐答案
试试这个:
如果您想使用多个提交按钮,那么你必须使用合格的FormCollection表单参数后动作像这样
If you want to use multiple submit button then you have to use pass FormCollection Form parameter to the post action like this
首先改变你的输入按钮的名称,如果你想使用多个提交按钮,以便改变你的提交按钮code喜欢这个它不能是相同的:
First change your input button name it cant be same if you want to use multiple submit button so change your submit button code to like this :
@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>
}
现在在操作Pagina_Details的Home控制器事件后写为:
Now On Home controller post event of the action Pagina_Details is written as :
[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();
}
我希望它的作品。
Hopefully its works.
这篇关于MVC4 Multibuttons在形式上不工作JQM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!