Handling parameters
Cobisi SEO Extensions makes your MVC action paramaters first class citizens in the world of URLs optimized for search engines. Not only
your MVC actions can have their parameters automatically handled as HTTP-GET (aka querystring) values, but they can also have them handled
by way of segments of the final URL. This means that the textual representation of selected parameters can be easily included in the URLs
that your web application handles, with much higher chances of a better search engine ranking.
While action parameters are handled as HTTP-GET (querystring) values by default, you should decorate them with the
Route.Param
attribute to have them
handled as segments of the final URL.
In the following block of code, for example, the
cityName parameter will be part of the final URL and the action could be
accessed with an address like
<Website root>/cheap-packages/venice
:
public class TravelController : Controller
{
[Route.Action("~/cheap-packages")]
public ActionResult FindPackages([Route.Param] string cityName)
{
// TODO: Make something useful
return Content("A fine travel can't be too cheap.");
}
}
Of course, multiple parameters can be handled as segments of the final URL and regular, HTTP-GET (querystring) parameters can coexist
with the former ones.
The MVC action defined below could thus be accessed with URLs like
<Website root>/cheap-packages/italy/venice
or
<Website root>/cheap-packages/italy/rome?includeHoaxes=true
:
public class TravelController : Controller
{
[Route.Action("~/cheap-packages")]
public ActionResult FindPackages([Route.Param] string countryName,
[Route.Param] string cityName,
bool? includeHoaxes)
{
// TODO: Make something useful
return Content("A fine travel can't be too cheap.");
}
}
Visual feedback in the IDE
As soon as you decorate your MVC action parameter with the
Route.Param
attribute, Cobisi SEO Extensions updates the visual feedback
it previously added to the IDE and shows how the final route will look like.