1

I write ASP.NET MVC application and I found out for me an interesting thing. When I use in View:

@using (Html.BeginForm("Login", "Home", FormMethod.Post))

a method Login of class HomeController is called. But if I write this html into View:

<form action="@Url.Action("Login", "Home")" method="post">

(form action is leading to the same action of the same controller) it is Index action called instead. Why? In both cases the same html below is rendered:

<form action="/Home/Login" method="post">

Thanks

2 Answers 2

3

nothing is wrong there. all expected behavious. @Url.Action("Login", "Home") returns string representation of your the action you write there.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, there must be some other probelm in my project, in the empty clean project it is working as expected... :/
2

Well, may be for others - I've bought a html template, not for a small money, but the problem was, the button was out of the form tag. So Index action was executed instead.

Comments

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.