3

所以,我有一个接受字符串和对象的方法,该对象具有 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);
    }

网址:

例如:http ://www.domain.com/mycontroller?name=Mike&age=29&jobId=&Fullname=&Find=Find

我怎样才能摆脱 jobId 和 Fullname 和 Find?

4

1 回答 1

0

我最终使用客户端 javascript 过滤表单数据,从而避免了任何不必要的或空的查询参数。

于 2013-02-24T04:34:34.190 回答