开发者

How should I handle multiple buttons in my action?

开发者 https://www.devze.com 2023-01-09 18:27 出处:网络
I have a form like this: <asp:Content ID=\"Content2\" ContentPlaceHolderID=\"MainContent\" runat=\"server\">

I have a form like this:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("Edit", "Order", FormMethod.Post, new{id="EditForm开发者_如何转开发"})) 
{%>
<input type="hidden" id="ButtonAction" name="ButtonAction" />
  <div id="orderbuttons">
    <div id="previous">
      <input type="image" name="BtnImage" value="Previous" src="previous.gif" />
      <input type="image" name="BtnImage" value="Save" src="save.gif" />
      <input type="image" name="BtnImage" value="Next" src="next.gif" />
    </div>
  </div>
<% } %>
</asp:Content>

My corresponding action is similar to:

    public ActionResult Edit(OrderModel model, string BtnImage)
    {
        switch (BtnImage)
        {
            case "Previous":
                break;
            case "Save":
                break;
            case "Next":
                break;
        }

        return View(model);
    }

The net effect is that this feels like I have a single action that is comprised of 3 actions. Can anyone suggest what I might change to make improve this?


Just have a function for each case and call those functions in the ActionResult method. Then ActionResult becomes a simple dispatcher rather than comprising three actions by itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消