How much to use @ Html.ActionLink or Javascript

1

I'm having trouble understanding when to use @Html.ActionLink or javascript:document.getElementById('Comercial').submit()

For example:

<a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">

         <li><a>@Html.ActionLink("Painel Inicial", "Index_Comercial", "Home")</a></li>

</ul>

Or:

using (Html.BeginForm("Index_Comercial", "Home", FormMethod.Post, new { id = "Comercial" }))
{

}
<a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">

         <li><a href="javascript:document.getElementById('Comercial').submit()">Painel Inicial</a></li>

</ul>
  • When to use one, or other?
  • What are the main differences?
asked by anonymous 09.11.2016 / 16:50

1 answer

1
___ erkimt ___ How much to use @ Html.ActionLink or Javascript ______ qstntxt ___

I'm having trouble understanding when to use @Html.ActionLink or <a>

For example:

<ul class="nav child_menu">

         <li><a>@Html.ActionLink("Painel Inicial", "Index_Comercial", "Home")</a></li>

</ul>

Or:

<a href="javascript:document.getElementById('Comercial').submit()">Painel Inicial</a>
  • When to use one, or other?
  • What are the main differences?
______ ___ azszpr164450

Well, this usage is incorrect:

<ul class="nav child_menu">

         <li><a>@Html.ActionLink("Painel Inicial", "Index_Comercial", "Home")</a></li>

</ul>

<a> already generates </a> . You do not need to put @Html.ActionLink() and%% GET around him. POST % generates a traditional link whose request method is 'Comercial' , the standard protocol.

Already this:

<a href="javascript:document.getElementById('Comercial').submit()">Painel Inicial</a>

makes the link change behavior and start to work with the method <input type='submit' /> , which requires a form to function (in this case, %code% ). In this case, the link behavior will be the same as a %code% .

    
___
09.11.2016 / 17:35