【问题标题】:ASP.NET MVC Image Button Inside HTML.BeginForm ProblemHTML.BeginForm 内的 ASP.NET MVC 图像按钮问题
【发布时间】:2010-08-23 16:36:41
【问题描述】:

我正在开发一个 ASP.NET MVC 2 门户。我的要求如下:

<form action = "mvc2proj/ControllerName/ActionName/1234" method="post">
  CheckBox 1 to select first item
  CheckBox 2 to select second item
  CheckBox 3 to select third item
  CheckBox 4 to select fourth item
  "Buy Now" image button
</form>

我正在使用 HTML.BeginForm() 生成“表单”元素:

<%Html.BeginForm("ActionName", "ContrllerName", new {id=1234}, FormMethod="Post");%>

当我使用 HTML 提交按钮时,我能够在“ControllerName”控制器的“ActionName”操作上获取表单值。但是因为它应该是一个图像按钮而不是常规的 HTML 提交按钮。

那么我怎样才能在 HTML.BeginForm() 中使用 IMAGE BUTTON 呢?

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    这应该可行。您的表格:

    <% using (Html.BeginForm("MyAction", "Home")){ %>
    
    <%=Html.CheckBox("Item1") %>
    <%=Html.CheckBox("Item2") %>
    <%=Html.CheckBox("Item3") %>
    <%=Html.CheckBox("Item4") %>
    
    <button name="button"><img src="yourimage.png" /></button>
    
    <% } %>
    

    以及对应的动作:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult MyAction(string Item1, string Item2, string Item3, string Item4)
    {
        return View();
    }
    

    【讨论】:

    • 是的...你是对的。我已经看到了这个解决方案。但智能感知不显示 SubmitImage 帮助函数。我使用的是 MVC 2,我的开发环境是 VS2010。
    • 我的错。更新了我对可行的答案。对此感到抱歉。
    • 为什么我们不用 input type=image HTML 提交按钮?它对我有用。
    猜你喜欢
    • 2010-11-03
    • 2021-11-01
    • 2014-06-03
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多