所以,我有一个接受字符串和对象的方法,该对象具有MVC转换为查询字符串参数的值,我的问题是在哪里以及如何摆脱空的参数,以便我的网址更清晰。
形式:
@using (@Html.BeginForm("Index", "ControllerName", FormMethod.Get,
new { enctype = "multipart/form-data", id = "form2" }))
//Should I do a check in here for null values before getting the request?
路由链接:
routes.MapRoute
(
"Default",
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", id = UrlParameter.Optional }
);
类别:
class formModel{
public string name {get;set;}
public int? age {get;set;}
public Guid? jobId{get;set;}
public string Fullname {get;set;}
}
对象属性:
formModel{
name: "Mike",
age: 29,
jobId: null,
Fullname: ""
}
控制器操作:
[HttpGet]
public ActionResult Index(string sortByText, SearchFormModel formModel)
{
var model = new SomeViewModel();
model.FormModel = formModel;
//etc
return View(model);
}
地址:
示例:http://www.domain.com/mycontroller?name=Mike&age=29&jobId=&Fullname=&Find=Find
如何摆脱jobId和Fullname以及Find?
答案 0 :(得分:0)
我最终使用客户端javascript过滤表单数据,这避免了任何不必要或空的查询参数。