Saturday, 15 March 2014

asp.net mvc - C# MVC Post method on bootstrap dropdown list -


On a bootstrap drop down list, I want to post one for a different action result. I tried to use the HTML initialization form to post but it did not work. See the code below.

Before:

  & lt; Div class = "orderbutton btn-group" & gt; & Lt; Button class = "BTN BTN-Primary BTN-LG Dropdown-Toggle" type = "button" Data-toggle = "dropdown" aria-expanded = "false" & gt; Place order & lt; Span class = "caret" & gt; & Lt; / Span & gt; & Lt; / Button & gt; & Lt; Ul class = "dropdown-menu" role = "menu" & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; An order & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "#" & gt; Order two & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt;  

Try my:

  & lt; Div class = "orderbutton btn-group" & gt; & Lt; Button class = "BTN BTN-Primary BTN-LG Dropdown-Toggle" type = "button" Data-toggle = "dropdown" aria-expanded = "false" & gt; Place order & lt; Span class = "caret" & gt; & Lt; / Span & gt; & Lt; / Button & gt; & Lt; Ul class = "dropdown-menu" role = "menu" & gt; @Usage (Html.BeginForm ("Home", "OrderOne", FormMethod.Post)) {& lt; Li & gt; & Lt; A & gt; Order one & lt; / A & gt; & Lt; / Li & gt; }using (Html.BeginForm ("Home", "OrderTwo", FormMethod.Post)) {& lt; Li & gt; & Lt; One & gt; Order two & lt; / A & gt; & Lt; / Li & gt; } & Lt; / Ul & gt; & Lt; / Div & gt;  

You can use ActionLink here.

  & lt; Ul class = "dropdown-menu" role = "menu" & gt; & Lt; Li & gt; @ AjaxActionLink ("order one", "order on", "home", new ajax option {htmp method = "post"}) & lt; / Li & gt; & Lt; Li & gt; @ Ajax.exeLink ("order two", "order-to", "home", new ajax option {http method = "post"}) & lt; / Li & gt; & Lt; / Ul & gt;  

No comments:

Post a Comment