coure2011
coure2011

Reputation: 42394

How do I pass an ID to the controller in ASP.NET MVC?

I have 4-5 partial view files (.ascx) like abc.ascx, cde.ascx, fgh.ascx.

I want to return different partial views based on the name of the view passed to url parameter like the following:

/someservice/abc will go to action someservice and will return abc.ascx partial view.
/someservice/cde will go to action someservice and will return cde.ascx partial view.

How can achieve this?

Upvotes: 0

Views: 279

Answers (1)

David Neale
David Neale

Reputation: 17018

Try this... (untested, if it doesn't work let me know and I'll have a play with it)

In your Global.asax.cs, above the default route, map this route:

 routes.MapRoute(
       "SomeService",
       "Home/SomeService/{view}",
     new { controller = "Home", action="SomeService", view = "" }
    );

In your controller:

 public class HomeController : Controller
 {
     public ActionResult SomeService(string view)
     {
         return View(view);
     }
 }

Call it with Home/SomeService/abc etc...

Upvotes: 1

Related Questions