Asp.net mvc T4MVC Html.BeginForm具有多个输入提交

Asp.net mvc T4MVC Html.BeginForm具有多个输入提交,asp.net-mvc,model-binding,t4mvc,html.beginform,input-button-image,Asp.net Mvc,Model Binding,T4mvc,Html.beginform,Input Button Image,控制器 [HttpPost] public virtual ActionResult PickAColour(ColourModel model, string imgbtn, string returnUrl) { 而这个观点 @using (Html.BeginForm(MVC.Home.PickAColour(Model,"",(string)ViewBag.ReturnUrl))) { @Html

控制器

[HttpPost]
public virtual ActionResult PickAColour(ColourModel model, 
                                        string imgbtn, string returnUrl) {
而这个观点

@using (Html.BeginForm(MVC.Home.PickAColour(Model,"",(string)ViewBag.ReturnUrl))) {
    @Html.LabelFor(m => m.SomeProperty)
    @Html.TextBoxFor(m => m.SomeProperty)
    ...
    ...
    <p>Now pick a colour</p>
    <input type="image" name="imgbtn" src="@Links.Content.Images.A_png" value="A"/>
    <input type="image" name="imgbtn" src="@Links.Content.Images.B_png" value="B"/>
    <input type="image" name="imgbtn" src="@Links.Content.Images.C_png" value="C"/>
    <input type="image" name="imgbtn" src="@Links.Content.Images.D_png" value="D"/>
    <input type="image" name="imgbtn" src="@Links.Content.Images.E_png" value="E"/>
    <input type="image" name="imgbtn" src="@Links.Content.Images.F_png" value="F"/>
} 
@使用(Html.BeginForm(MVC.Home.PickAColour(Model,“,(string)ViewBag.ReturnUrl))){
@LabelFor(m=>m.SomeProperty)
@Html.TextBoxFor(m=>m.SomeProperty)
...
...
现在选择一种颜色

}

现在,这将不起作用,因为我没有将imgbtn参数传递到方法中。我不知道正确的方法是什么

必须使用正确的重载方法:

@Html.BeginForm(MVC.Home.ActionNames.PickAColour, MVC.Home.Name,
                new { imgbtn = "", returnUrl = (string)ViewBag.ReturnUrl },
                FormMethod.Post, null)

对于复杂模型对象
model
,不能使用上面的路由值传递它。单击“提交”按钮时应提交此文件,以便ASP.NET MVC Model Binder可以执行其工作。

我使用您的方式进行了测试,它会运行,但在调试进入PickAColour方法时仍会显示字符串imgbtn=null。看起来和我最初的方法调用的结果一样?顺便说一下,模型对象实际上在这两种方式中都很好,returnUrl也很好。只有imgbtn参数似乎未连接。请尝试更改此参数的名称以进行测试。。。为输入输入输入一个id=“imgbtn”,然后重试。已确认。image button type=“image”是导致问题的原因。MVC只能注册type=“submit”,因为按钮可以解析其值。什么?!我不知道。有没有办法用我的彩色按钮,而不是无聊的窗口灰色按钮来解决这个问题呢?我以前用过一种可能性: