It fires imm...">

Why does ASP.NET MVC launch href onclick immediately?

<a href="" onclick="@{ MultiLanguageProvider.Instance.SwapLanguage(); }">

It fires immediately when the page loads. What for?

+4
source share
2 answers

Not sure what to withdraw @{ MultiLanguageProvider.Instance.SwapLanguage(); }. I would suggest that this is javascript. You could try the following:

<script>
function doClick() {
@{ MultiLanguageProvider.Instance.SwapLanguage(); }
}
</script>

<a href="" onclick="doClick();">
+1
source

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

All Articles