2

In my View I am using this form method:

<form method="get" action="@Url.Action("Index")">

So "Index" is method in Controller - UserA:

public ActionResult Index(SearchParameters parameters, UserModel userModel)

My question is, how to add in this same View new form method, where I want to call action in different Controller, so I would for example call ... action="@Url.Action("Index2") ... Where Index2 is ActionResult Index2 ... in Controller - UserB.

Thanks for explanation...

4

1 回答 1

4

Url.Action has an overload that takes a controller name as the second parameter, so you should be able to copy your existing code and add that second parameter:

<form method="get" action="@Url.Action("Index", "UserB")">

By the way, you can simplify your code even further by using the HtmlHelper BeginForm extension method, which has the same overload:

@using (Html.BeginForm("Index")) {
    // form fields here
}

and

@using (Html.BeginForm("Index", "UserB")) {
    // form fields here
}

That will render your <form> structure for you.

于 2014-06-11T13:46:45.307 回答