Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  37] [ 4]  / answers: 1 / hits: 78355  / 10 Years ago, tue, november 4, 2014, 12:00:00

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()



Here is my view:



@model PriceCompare.Models.QuoteModel

@{
ViewBag.Title = Quote;
}

<h2>Quote</h2>

@if (@Model.clarify == true)
{
// do drop down loic
@:ShowClarify();
}
else
{
// fill quote
@:ShowQuote();
}
<div class=clarify>

You can see the clarify div
</div>
<div class=quote>

You can see the quote div
</div>

@section head {

<script type=text/javascript>

$(document).ready(
function ShowQuote() {
$(.quote).show();
},
function ShowClarify() {
$(.clarify).show();
}
);

</script>
}


Is it because I have nested it in an `@if'? Anyway around this?


More From » jquery

 Answers
120

You need to put your javascript in a <script> tag, and you need to call the functions within their scope:



<script type=text/javascript>

$(document).ready(
function ShowQuote() {
$(.quote).show();
},
function ShowClarify() {
$(.clarify).show();
}

@if (@Model.clarify == true)
{
// do drop down loic
ShowClarify();
}
else
{
// fill quote
ShowQuote();
}
);

</script>

[#68917] Saturday, November 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billie

Total Points: 101
Total Questions: 114
Total Answers: 98

Location: Burundi
Member since Wed, Nov 25, 2020
4 Years ago
;