5
\$\begingroup\$

When the user clicks the first button ('Back to List' button), I redirect the user to the Employee List page. Can you please review this and suggest if there is any better way of achieving the same?

@using (@Html.BeginForm("Edit", "Employee", FormMethod.Post, new { id = "editEmployeeForm" }))
{
    <div class="form-group">
        @Html.LabelFor(emp => emp.FirstName)
        @Html.TextBoxFor(emp => emp.FirstName)
    </div>
    <div class="form-group">
        @Html.LabelFor(emp => emp.LastName)
        @Html.TextBoxFor(emp => emp.LastName)
    </div>
    <div class="form-group">
        <button type="button" class="btn btn-default" onclick="location.href='@Url.Action("Index", "Employee")'">Back to List</button>
        <button type="submit" class="btn btn-primary">Update</button>
    </div>
}

I am concerned about the first button, however if you have feedback for any other code as well, please mention that.

\$\endgroup\$
  • 1
    \$\begingroup\$ You could replace the button with an anchor tag and use the Url helper to create the back url. <a href="@Url.Action("Index", "Employee")">Back to list</a> \$\endgroup\$ – user1320170 Aug 7 '15 at 13:17
5
\$\begingroup\$

Semantically, HTML button tags are supposed to represent a user's action, whereas the link tags are supposed to take care of the navigation between pages.

That said, as @user1320170 pointed out in comments, your tag should be a link (< a > tag.)

You'll notice it's much clearer this way.

Apart from that, your code is good, using @Url.Action("Index", "Employee") is a good plan.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.