我正在MVC中构建商店定位器。这是我的控制器:
namespace IWOOv4.Controllers
{
public class StoreListingController : Controller
{
// GET: StoreListing
public ActionResult Index()
{
return View();
}
public ActionResult Details(string zip)
{
List<Site> result = SiteMgmt.GetByZip(zip);
View().ViewData["sites"] = result;
return View();
}
public ActionResult Details(string city, string st)
{
List<Site> result = SiteMgmt.GetByCity(city, st);
View().ViewData["sites"] = result;
return View();
}
}
}
这是我的观点:
@{
ViewBag.Title = "Home Page";
}
<div class="container">
<div class="row">
<!--HEADER-->
</div>
<div class="row sub-header">
<span>ONLINE ORDERING</span>
</div>
<div class="row container-text">
Find Your Store
</div>
<div class="row">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="search">
<div class="input-group-btn">
<button class="btn btn-default" type="button" id="searchbutton">
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</div>
</div>
<div class="row">
<!--FOOTER-->
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#searchbutton').on('click', function (event) {
document.location = '@Url.Action("Details", "StoreListingController")';
});
});
</script>
当我调用我的Controller操作时,它不显示我的商店列表。它将我的网址从http://localhost/IWOOv4/Home/Index
更改为http://localhost/IWOOv4/StoreListingController/Details
。我抬头看看如何调用控制器动作到你的视图和我的方式似乎没问题。我做错了什么?非常感谢!
答案 0 :(得分:0)
不要将Controller
后缀添加到Url.Action
的第二个参数,MVC会在创建路径时为您执行此操作:
document.location = '@Url.Action("Details", "StoreListing")';
答案 1 :(得分:0)
在控制器上最多只能有2个具有相同名称的操作方法,为此,1必须是[HttpPost],另一个必须是[HttpGet]
您可能需要在此处查看答案:
Routing: The current request for action [...] is ambiguous between the following action methods