#3 Passing Parameters to Action

We can define parameters that has to be passed to Action Methods in MapRouteMethod,


routes.MapRoute(
"Search",
"{controller}/{name}/{id}",
new{ controller = "Search",action ="Cusine", name = "",id=0}
);

In the above example we define two parameters name and id to the action method Cusine. 

To pass complex object we need to pass each property in the URL,this will get mapped to corresponding model in Action Method:


routes.MapRoute(
"Search",
"{controller}/{name}/{id}",
new{ controller = "Search",action ="Cusine", name = "",id=0}
);

---Action Method

public ActionResult Cusine(MyModel model)
{
return Content("Hello"+model.Name+model.id);
}

public class MyModel
{
public String Name { get; set; }
public int id { get; set; }
}


	

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s