LLF
LLF

Reputation: 707

ASP.NET MVC: Is it possible to send custom route value with every form submiting?

I have my custom route like this

routes.MapRoute(
            name: "child",
            url: "{parcontroller}/{controller}/{action}/{id}",
            defaults: new { id = UrlParameter.Optional },
            constraints: new { }
        );

When i'am in page

http://localhost:1234/Product/Beverage/Browse/10

Is it possible to send "Product" as parcontroller's route value everytime i submit with BeginForm (Not BeginRouteForm) or click on actionlink in this page.

Upvotes: 0

Views: 731

Answers (1)

avidenic
avidenic

Reputation: 643

Did you check attribute routing?

Defining routes got easier with MVC 5.

[RoutePrefix("Prodcut/{productId}")]
public class ProductController: Controller
{
    [Route("Beverage/Browse/{beverageId}")]
    public ActionResult BrowseBeverage(int productId, int beverageId) { /* ... */ }    
}

your route will now look like this:

http://localhost:1234/Product/1/Beverage/Browse/10

check more here: http://attributerouting.net/

Upvotes: 1

Related Questions