Can I give SEO-friendly URL Segment's to action on a PageController?

310 views Asked by At

Is it possible to define the URL segment for an action on a PageController<T>?

Take for example the following controller,

public class MyPageController : PageController<MyPageData>
{
    public ActionResult Index(MyPageData currentPage)
    {
        return View(currentPage);
    }

    [HttpPost]
    public ActionResult SubmitForm(MyPageData currentPage, FormModel model)
    {
        // ...
        return Redirect("/");
    }
}

New, let's say we've created an instance of MyPageData at the URL /my-page, if we render a form who's action is the SubmitForm action, we'll get a URL like so <form action="/my-page/SubmitForm">

@using(Html.BeginForm("SubmitForm"))
{
    ...
}

My question is, is there any way to define or control how the URL segment for the non-Index action is rendered, so the form would render like so <form action="/my-page/submit-form">?

1

There are 1 answers

1
Henrik N On BEST ANSWER

You should be able to use the standard ASP.NET action name attribute, such as

public class MyPageController : PageController<MyPageData>
{
    [HttpPost]
    [ActionName("submit-form")]
    public ActionResult SubmitForm(MyPageData currentPage, FormModel model)
    {
        // ...
        return Redirect("/");
    }
}