我是ASP.NET MVC的新手,目前,我参与了在ASP.NET MVC 2中开发一个新的应用程序。我在管理来自dBase的长查询字符串参数时遇到了问题。
例如,在任何非mvc应用程序中,以下URL运行良好:
http://example.com/test.aspx?first_name = fname& last_name = lname& email_id = email& address1 = add1& address2 = add2& city = city& state = state& zip_code = zip等。
QueryString参数可以即时确定(即在运行时)。现在为动态QueryString如何进行路由?
对于简单的URL,URL将如下所示(在ASP.NET MVC中):
http://example.com/test/id/category
但对于上面提到的动态& long QueryString URL的外观如何?是否所有QueryString参数都通过斜杠(/)?
分隔提前感谢您的帮助。
最诚挚的问候,
Vikas Anand
答案 0 :(得分:0)
您的网址将如下所示:
http://example.com/test/id/category?first_name = fname& last_name = lname& email_id = email& address1 = add1& address2 = add2& city = city& state = state& zip_code = zip
答案 1 :(得分:0)
您可以在global.asax中编写路线。假设查询参数的顺序永远不会改变并且始终存在。这个例子假设HomeController:
routes.MapRoute
(
"myExample", // route name
"Home/Test/{id}/{first_name}/{last_name}/{email_id}/{address1}/{address2}/{city}/{state}/{zip}, // url pattern
new { controller = "Home", action = "Test", id = "", first_name = "", last_name = "", email_id = "", address1" = "", address2 = "", city = "", state = "", zip = "" } // param defaults
);
的HomeController /测试
public ActionResult Test(int id, string first_name, string last_name, int email_id, string address, string address2, string city, string state, string zip) {}