0

我正在开发一个 MVC 应用程序。

在编辑视图中,我想要保存/提交按钮和取消按钮。

默认情况下,MVC 给出“返回列表”链接。此链接调用 index() 方法。

现在,我想在取消按钮的 Onclick 事件上调用这个 index() 方法,该怎么做?

<input type="submit" value="Save" onclick="return validate();" id="btnSubmit" />  
<input type="Button" value ="Cancel" onclick="Index()"style=" font-size:"1.2em"/>

我必须在上面的代码中进行哪些更改?

4

1 回答 1

4

您可以使用window.location.href重定向到指定的 url:

<input type="Button" value="Cancel" onclick="window.location.href='@Url.Action("index")'" style=" font-size:"1.2em"/>

或者简单地使用锚而不是按钮:

@Html.ActionLink("Cancel", "Index")
于 2013-03-11T12:26:50.523 回答