Why does ASP.NET MVC launch href onclick immediately?
2 answers
Fire during page load
with this code
<a href="" onclick="@{ MultiLanguageProvider.Instance.SwapLanguage(); }">
@{ MultiLanguageProvider.Instance.SwapLanguage(); } is a C # code code that runs immediately . It will execute normally, as you should, you call a method, it will actually call a method on your server side. The result of this method will be returned if it simply executes its void.
, javascript , ajax- .
, .
-
public string SwapLanguage()
{
return "testString";
}
<a href="" onclick="@{ MultiLanguageProvider.Instance.SwapLanguage(); }">
<a href="" onclick="testString">
+1