suppose i have link like www.mysite.com/Certificate/data/C001-P2003
my controller name is Certificate and action name data
public class CertificateController : Controller
{
public ActionResult Data(string certid,string studid)
{
return View();
}
}
i want to know what i need to develop which will extract id and break into two part separated by hyphen and map two data to Data action.
C001 will map to certid and P2003 will map to studid. so i need concept how to do it?
do i need to develop any action filter ?
do i need to write any custom value provider ?
do i need to write any custom model binder ?
i do not want to break the data inside action rather i want to do it out of action. so suggest me something best idea. thanks
Create a convention in your RouteConfig
that will map the route you want.
routes.MapRoute(
name: "CertificateData",
url: "Certificate/data/{certid}-{studid}",
defaults: new { controller = "Certificate", action = "Data"}
);
Or enable Attribute Routing and use template on action to match the desired url
// GET Certificate/data/C001-P2003
[Route("Certificate/data/{certid}-{studid}")]
public ActionResult Data(string certid,string studid) {...}