【发布时间】:2010-05-25 15:23:31
【问题描述】:
我正在尝试构建一个小型 ASP.NET MVC 2 应用程序。我有一个控制器类,其中包含以下方法
public ActionResult Index()
{
TestMvc.Models.PersonalInformation objPerson = new TestMvc.Models.PersonalInformation();
objPerson.FirstName = "Shyju";
objPerson.LastName = "K";
objPerson.EmailId="shyju@company.com";
return View(objPerson);
}
当页面(视图)被调用时,我可以在那里看到这些数据,因为我的视图显示了这些数据。现在我想知道如何在 url 中传递查询字符串并使用该 id 来构建 PersonalInformation 对象。我可以读取查询字符串值吗?在哪里阅读?
我希望 questrtstring 像 http://www.sitename/user/4234 其中 4234 是用户 ID
【问题讨论】:
-
如果您确实需要使用查询字符串提交一些数据,您必须将表单操作更改为“获取”(而不是发布)。在公共 ActionResult Index() 上,您可以验证 Request.QueryString["YourField"] != null 是否。但我更喜欢在您的场景中使用 RouteData.Values
标签: asp.net-mvc-2 query-string