tags:

views:

39

answers:

1

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 this
/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?

A: 

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...

David Neale
Not working, getting this error: The RouteData must contain an item named 'controller' with a non-empty string value.
coure06
See updated: controller = "Home", action="SomeService", view = ""
David Neale