[英]How to remove empty parameters in querystring asp.net mvc
So, I have a method that accepts a string and an object, the object has values that MVC translates into querystring parameters, my question is where and how can I get rid of the parameters that are empty so my url is cleaner. 所以,我有一个接受字符串和对象的方法,该对象具有MVC转换为查询字符串参数的值,我的问题是在哪里以及如何摆脱空的参数,以便我的网址更清晰。
Form: 形成:
@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?
Routing Link: 路由链接:
routes.MapRoute
(
"Default",
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Class: 类:
class formModel{
public string name {get;set;}
public int? age {get;set;}
public Guid? jobId{get;set;}
public string Fullname {get;set;}
}
Object properties: 对象属性:
formModel{
name: "Mike",
age: 29,
jobId: null,
Fullname: ""
}
Controller action: 控制器动作:
[HttpGet]
public ActionResult Index(string sortByText, SearchFormModel formModel)
{
var model = new SomeViewModel();
model.FormModel = formModel;
//etc
return View(model);
}
Url: 网址:
example: http://www.domain.com/mycontroller?name=Mike&age=29&jobId=&Fullname=&Find=Find 示例: http : //www.domain.com/mycontroller?name = Mike &age = 29&jobId =&Fullname =&FIND>查找
How can I get rid of jobId and Fullname and Find? 如何摆脱jobId和Fullname以及Find?
我最终使用客户端javascript过滤表单数据,这避免了任何不必要或空的查询参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.