How do I access a Post method without a submit button
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)开发者_C百科]
public ActionResult dataAccess()
{
//...
}
SideMenu.ascx ...
<%= Html.ActionLink("Witness", "Witness", "Loss")%>
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>
Using Jquery:
$('#MyFormId').submit();
or
$('#MyButtonId').click();
One way would be to trigger click on your button via javascript (jquery makes it really easy)
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>
精彩评论