asp.net MVC : Pass query string as a string, 还是个别参数?

标签 asp.net asp.net-mvc query-string

在 asp.net MVC 中,我的 Controller 中有一个搜索操作,我试图决定是否应该将查询作为字符串传递到我的存储库

public ActionResult Search(string query)
{
    return View(_repository.ListPeople(query));
}

或作为单独的参数:

public ActionResult Search(string FirstName, string LastName, System.Nullable<byte> Education)
{
    return View(_repository.ListPeople(FirstName, LastName, Education));
}

我在网上看到的很多例子都使用查询字符串方法,但对我来说它并不“安全”,尽管当你有一堆参数要传入时它更容易处理一些。对于执行此操作的更好方法是否已达成普遍共识?

最佳答案

我赞成模型绑定(bind)。这样,如果您决定添加额外的搜索选项,除了模型类之外,您无需进行任何更改。

信息 herehere

关于asp.net MVC : Pass query string as a string, 还是个别参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1160453/

相关文章:

asp.net - 如何在单选按钮前显示单选按钮标签?

asp.net - 预期表达

oauth-2.0 - OAuth2 : query string vs. 片段

c# - Entity Framework - 对业务层需求的意见

Javascript If语句运行一些html代码

asp.net-mvc - 带有点的表单元素的MVC Controller 参数?

ruby-on-rails - 适用于Ruby on Rails开发人员的ASP.NET MVC?

jquery - 使用 PartialView 的 MVC 5 JQuery Bootstrap Modal

svg - xlink中的&符号(&):href attributes of SVG images?

javascript - 从 url 中删除查询参数