Ctr*_*eat 1 c# asp.net-mvc razor asp.net-mvc-3
我的 cshtml 页面上有两个按钮 -Agree
以及Disagree
- 如何轻松地将这些值传递回我的控制器,以便我可以决定将它们带到主页或将它们注销。
所以在我的 cshtml 页面上我有......
<input type="button" name='Agree' value="I Agree"
onclick="location.href='@Url.Action("DoAccept", "Home")'" />
<input type="button" name='Delete' value="I Disagree"
onclick="location.href='@Url.Action("DoAccept", "Home")'" />
Run Code Online (Sandbox Code Playgroud)
所以在我的家庭控制器中,我有一个 DoAccept 方法,如下所示:
public ActionResult DoAcceptTC()
{
//if( buttom clicked was Agree)
return RedirectToAction(VIEW_HOMEPAGE);
//else
//return Logout page..
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何轻松地将值返回到控制器方法?
在没有 html 表单托管输入的情况下使用输入没有多大意义。您可以使用表单或简单的链接
//view
@using(Html.BeginForm("DoAccept"))
{
<button name="decision" value="agree">I Agree</button>
<button name="decision" value="disagree">I disagree</button>
}
//controller
public ActionResult DoAcceptTC(string decision)
{
//decision == "agree"
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13053 次 |
最近记录: |