i am trying to create route.
Which is
/emlak/TITLE/number.aspx
such as
/emlak/Here_is_your_best_property/123456.aspx
Global.asax:
routes.MapRoute(
"Product",
"{controller}/{deli}/{productId}",
new { controller = "emlak", action = "Index" },
new { productId = UrlParameter.Optional , deli = UrlParameter.Optional }
);
My controller
namespace emrex.Controllers
{
public class EmlakController : Controller
{
//
// GET: /Emlak/
public ActionResult Index(String productId, String deli)
{
return View();
}
}
}
and i am getting next error:
Server Error in '/' Application.
The resource cannot be found.
Thanks for help.
Best Answer
Don't provide URL parameter defaults as constraints (as you did)
When you define your route as (I added additional comments so we know what each part is)
So basically you shouldn't provide constraints in your case which makes it meaningless. Put the last two in route defaults and keep constraints out of this route defintion as:
This should definitely work unless you have some other route definitions or don't use code that you provided.