views:

29

answers:

3

Hello All,

I am very new to ASP.NET MVC and currently, I am involved in developing a new application in ASP.NET MVC 2. I am having problem in managing a long querystring parameters that comes from dBase.

For example, in any non-mvc app the following URL works well:

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 and so on.

The QueryString parameter can be determined on the fly (i.e. at run-time). Now for dynamic QueryString how routing will be done?

Also for a simple URL, the URL will be as follows (in ASP.NET MVC):

http ://example.com/test/id/category

But for above mentioned dynamic & long QueryString how the URL will look like? Will all the QueryString parameters be separated through slash (/)?

Thanks in advance for your help.

Best Regards,

Vikas Anand

A: 

Your url would look like this:

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

chbu
A: 

Thanks for the quick reply CHBU....it helps me a lot :)

vikas anand
There's `add comment` option under the question/answers in case You didn't notice. Welcome on Stackoverflow. :)
Arnis L.
A: 

You could write a route in your global.asax. assuming the order of the query params never change and are always present. This example assumes 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/Test

public ActionResult Test(int id, string first_name, string last_name, int email_id, string address, string address2, string city, string state, string zip) {}
gnome