1

I am writing an app using ASP.NET MVC. I'm in a view that is located at:/orders/{orderId}. That view renders just fine. Inside of it though, I have a button inside of a form that looks like this:

<form action="/orders/{orderId}/flag" method="post">
  <button type="submit" class="btn">Flag</button>
</form>

In my controller, I have the following:

public class OrdersController : Controller
{
  public ActionResult Details(string id) 
  {
    var model = Orders.FindById(id);
    return View(model);
  }

  public ActionResult Flag(string id)
  {
    var model = Orders.FindById(id);
    model.Flag();
    return RedirectToAction(
  }
}

My question is, how do I use the ASP.NET MVC helpers to generate the path to my flag action? The action in my form is just a template at the moment which won't work. How do I address this scenario in my razor view?

Thanks!

1 Answer 1

1
@Url.Action("Flag", "Orders", new { id = [orderid here] })

I recommend using T4MVC, the you can do:

@Url.Action(MVC.Orders.Flag([orderid here])
Sign up to request clarification or add additional context in comments.

2 Comments

@atika - Interesting. I haven't used t4mvc before. when I try to use it though, I'm getting types generated instead of methods. Any ideas why this would happen?
T4MVC should generate types, so you're not using magic strings, but strongly typed code everywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.