Calling Javascript Function In Mvc 5 Razor View
I have seen in another post that you can call a JavaScript function in your razor code like so: @:FunctionName() For me though this only outputs the actual words FunctionName() He
Solution 1:
You need to put your javascript in a <script>
tag, and you need to call the functions within their scope:
<scripttype="text/javascript">
$(document).ready(
functionShowQuote() {
$(".quote").show();
},
functionShowClarify() {
$(".clarify").show();
}
@if (@Model.clarify == true)
{
// do drop down loicShowClarify();
}
else
{
// fill quoteShowQuote();
}
);
</script>
Solution 2:
If you are passing any parameter to the JavaScript function, it must be enclosed with quotes ('').
foreach (var item in files)
{
<scripttype="text/javascript">Attachment(**'@item.FileName'**, **'@item.Size'**);
</script>
}
Post a Comment for "Calling Javascript Function In Mvc 5 Razor View"