Asp.net mvc 提交表单后在URL中包含参数
我有搜索表单,现在提交后,网站会像这样返回视图和URLAsp.net mvc 提交表单后在URL中包含参数,asp.net-mvc,Asp.net Mvc,我有搜索表单,现在提交后,网站会像这样返回视图和URLhttps://localhost:44303/Product/Search,但我希望URL包含查询字符串https://localhost:44303/Product/Search?name=abc&brand=edf以便访问者可以复制和共享 -- view -- @using (Html.BeginForm("Search", "Product", FormMethod.Post) { <input id="name" name
https://localhost:44303/Product/Search
,但我希望URL包含查询字符串https://localhost:44303/Product/Search?name=abc&brand=edf
以便访问者可以复制和共享
-- view --
@using (Html.BeginForm("Search", "Product", FormMethod.Post)
{
<input id="name" name="name">
<input id="brand" name="brand">
<button type="submit">Search</button>
}
-- controller --
public ActionResult Search(SearchPara para)
{
// do stuff and return view + model
}
-- model --
class SearchPara {
public string name {get; set;}
public string brand {get; set;}
}
——查看--
@使用(Html.BeginForm(“搜索”、“产品”、FormMethod.Post)
{
搜寻
}
--控制器--
公共行动结果搜索(SearchPara)
{
//完成任务并返回视图+模型
}
--模型--
类搜索段落{
公共字符串名称{get;set;}
公共字符串品牌{get;set;}
}
通过将表单方法更改为“获取”,表单将提交给控制器的“搜索”操作并映射到模型
在您看来,这应该是新的形式:
@using (Html.BeginForm("Search", "Product", FormMethod.Get)
{
<input id="name" name="name">
<input id="brand" name="brand">
<button type="submit">Search</button>
}
将表单方法更改为
FormMethod.Get
,并将后端搜索逻辑移动到Get方法。
https://localhost:44303/Product/Search?name=abc&brand=edf