Url is invalid when View returns

Inside my controller, I return a View that works fine, except that Url is not what I expected, because it replaced with the name of the action method it is in.

http://hostname/Controller/SubmitTicket

instead of

http://hostname/Controller/Detail

And I cannot do a redirect to action in this case.

    public ActionResult Detail()
    {
        return View();
    }

    public ActionResult SubmitTicket()
    {
        return View("Detail");
    }

<h2>Detail</h2>

<% using (Html.BeginForm("SubmitTicket", "Home"))
   { %>
       <input id="Submit1" type="submit" value="submit" />
   <% } %>

+3
source share
1 answer

In MVC, the URL used will always be action-based.

I think you are doing a POST on http: // hostname / Controller / SubmitTicket , and then returning the Detail view. In this case, the URL will be the URL you submitted.

, URL-, SubmitTicket . , .

, Post/Redirect/Get pattern.

public ActionResult Detail()
{
    return View();
}

public ActionResult SubmitTicket()
{
    RedirectToAction("Detail")
}
+1

All Articles