tags:

views:

70

answers:

4

I am working on a MVC project that works fine when the submit button is clicked to access the Post method. I have a side menu that I would like to access the Post method and save the necessary changes before redirecting. How do I do that?

<fieldset>
    <% Html.RenderPartial("SideMenu", Model); %>
</fieldset>
<fieldset>
    //data with submit button
</fieldset>

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult dataAccess()
{
    //...
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult dataAccess()
{
    //...
}

SideMenu.ascx ...

<%= Html.ActionLink("Witness", "Witness", "Loss")%>
A: 

One way would be to trigger click on your button via javascript (jquery makes it really easy)

epitka
+1  A: 

You can add an onclick javascript method to the menu item in question.

<form name="myform" action="action.php" method="POST">
 <input> ... 
</form>

<ul id="menu">
  <li class="menuitem" onclick="javascript: document.myform.submit()">Do Stuff To Form</li>
</ul>
Wade Tandy
+2  A: 

Using Jquery:

$('#MyFormId').submit();

or

$('#MyButtonId').click();
Josh
A: 

You can have form with hidden data, and instead of action link use submit button, but style it as a link. This way you can have POST request without javascript, and it will look same to user.

E.g.

<form>
  <input type="submit" value="test" 
         style="text-decoration: underline; background: none; border: 0; cursor: pointer;"/>
</form>
queen3