如何在MVC4中添加按钮并重定向到另一个视图? [英] How to add button and redirect to another view in MVC4?
问题描述
我有一个疑问。
我有一个名为CustomerMaster的视图。在CustomerMaster视图中,我有字段''Area','City'等。如果城市已经在列表中,它将自动显示在下拉菜单中。
假设我需要的城市不在列表中,意味着我必须添加该城市。所以我决定在城市字段附近保留一个添加按钮。如果我单击该按钮,则需要重定向到该视图。那么我怎么能在MVC4中做到这一点?
1)我怎样才能让按钮靠近现场?
2)如何重定向点击mvc4中的按钮,从一个视图到另一个视图?
谢谢。
I have one doubt.
I have one view called CustomerMaster. In CustomerMaster view I have field Like 'Area', 'City' etc. If city is already in the list it will be automatically shown in the Dropdown .
Suppose the City which I need is not in the list, means I have to add that city. So I decided to keep one 'Add' button near to 'city' field. If I click that button it needs to redirect to that view. So how can i do this in MVC4?
1) How can I keep button near to the field?
2) How to redirect from one view to another view while clicking the button in mvc4?
Thanks .
推荐答案
看到这个您的查询的文章
MVC4不同的重定向技术(Razor) [ ^ ]
See this article for your query
MVC4 Different Redirection Techniques (Razor)[^]
您好,
尝试以下代码
您可以传递您的操作和控制器名称
Hi,
Try Below Code
You can pass your action and controller name
@Html.ActionLink("Home", "ActionName", "ControllerName")
您可以尝试下列任何一种方法
如Sanjay所述,创建一个这样的动作链接
You can try one of the following approch
As mentioned by Sanjay create an action link like this
@Html.ActionLink("Button name", "ActionName", "ControllerName")
应该有一个名称为 ControllerName的控制器以及下面的操作方法
There should be a controller with name ControllerName and an action method like below
public ActionResult ActionName()
{
return View();
}
或者您可以尝试这样:
Or you can try like this:
<input type='button' value='Dummy Button' id='myButton' onClick='redirectOnClick()' />
<script>
function redirectOnClick(){
document.location ='ControllerName/ActionName';
}
</script>
这篇关于如何在MVC4中添加按钮并重定向到另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!