Reputation: 42394
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
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