【发布时间】:2015-11-23 22:10:10
【问题描述】:
ASP.NET MVC4 搜索 Razor 局部视图定义为
@inherits ViewBase<MvcMusicStore.ViewModels.SearchViewModel>
@using (Html.BeginForm("Browse", "Store" , FormMethod.Get,
new { @class = "searchform" }))
{
@Html.TextBoxFor(model => model.Search, new
{
@class = "searchfield",
value = "Search..."
})
<input class="searchbutton" type="submit" value="@("Search...")" />
<input type="hidden" value="relevance" name="order" />
}
并在site.cshtml中使用:
@Html.Partial("Search", new MvcMusicStore.ViewModels.SearchViewModel())
如果页面地址是http://localhost:52223/Store/Browse/Kuupakkumine,则使用无效操作/Store/Browse/Kuupakkumine 创建搜索表单。 Kuupakkumine 会自动添加到 url 的末尾:
<form action="/Store/Browse/Kuupakkumine" class="searchform" method="get">
<input class="searchfield" id="Search" name="Search" type="text" value="Search...">
<input class="searchbutton" type="submit" value="Search...">
</form>
如何解决这个问题,以便正确的 url,/Store/Browse 将出现在浏览器 html 中?
Storecontroller Browse 方法签名是
[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
public ActionResult Browse(string category, string order, int? page, bool? descending,
int? itemsPerPage, string brand, string color, string @class, string type, bool? grid,
string search, bool? instock, CartLayout? cartLayout, string id)
【问题讨论】:
-
方法的签名是什么?
-
我不明白问题,哪个方法签名?
Html.BeginForm在 MVC 内置方法中 -
控制器方法-
public ActionResult Browse( what are the parameters? ) -
@StephenMuecke 我更新了问题并添加了浏览签名使用默认路由,因此 Kuupakkumine 作为 Id 参数传递给浏览,这将返回无效结果。如果从搜索中调用 Browse,则 id 必须为 null。浏览只需要填写搜索参数
-
假设你使用默认路由,那么
Html.BeginForm("Browse", "Store", new { id = "" }, FormMethod.Get, new { @class = "searchform" }))
标签: asp.net-mvc asp.net-mvc-4 razor asp.net-mvc-partialview razor-2