したがって、文字列とオブジェクトを受け入れるメソッドがあり、オブジェクトには、MVC がクエリ文字列パラメーターに変換する値があります。私の質問は、空のパラメーターをどこでどのように削除して、URL をよりクリーンにすることができるかです。
形:
@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);
}
URL:
例: http://www.domain.com/mycontroller?name=Mike&age=29&jobId=&Fullname=&Find=Find
jobId と Fullname と Find を取り除くにはどうすればよいですか?