Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 02, 2012 02:41 PM by mebinici
Participant
796 Points
446 Posts
Aug 01, 2012 05:50 PM|LINK
Can I do something like this?
<script type="text/javascript">
@{ if(Model.TotalFlags == 0) { <text> ShowMessage(); </text> } }
</script>
815 Points
256 Posts
Aug 01, 2012 08:15 PM|LINK
Well the syntax will fire, but where is your logic for the Model. Is it within a functions page or being declared on the same page?
ShowMessage(); is a javascript function, correct?
You will need to defind "Model" (which is your class), otherwise you will receive the YSoD or are you receiving and JS error?
All-Star
18647 Points
2647 Posts
Aug 01, 2012 09:22 PM|LINK
mebinici You will need to defind "Model" (which is your class), otherwise you will receive the YSoD or are you receiving and JS error?
You don't need to define Model, in MVC the Model property exists in the view and it gets set via a controller action method.
@BitShift - that code looks fine.
Aug 02, 2012 02:41 PM|LINK
CodeHobo is correct.
I thought this was for WebPages, doh!
BitShift
Participant
796 Points
446 Posts
Razor syntax with If statement inside of javascript with reference to model data?
Aug 01, 2012 05:50 PM|LINK
Can I do something like this?
<script type="text/javascript">
@{ if(Model.TotalFlags == 0) { <text> ShowMessage(); </text> } }</script>
mebinici
Participant
815 Points
256 Posts
Re: Razor syntax with If statement inside of javascript with reference to model data?
Aug 01, 2012 08:15 PM|LINK
Well the syntax will fire, but where is your logic for the Model. Is it within a functions page or being declared on the same page?
ShowMessage(); is a javascript function, correct?
You will need to defind "Model" (which is your class), otherwise you will receive the YSoD or are you receiving and JS error?
Love collecting video games, movies and board games!
Enjoying my '11 WRX, so sexy...
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Razor syntax with If statement inside of javascript with reference to model data?
Aug 01, 2012 09:22 PM|LINK
You don't need to define Model, in MVC the Model property exists in the view and it gets set via a controller action method.
@BitShift - that code looks fine.
Blog | Twitter : @Hattan
mebinici
Participant
815 Points
256 Posts
Re: Razor syntax with If statement inside of javascript with reference to model data?
Aug 02, 2012 02:41 PM|LINK
CodeHobo is correct.
I thought this was for WebPages, doh!
Love collecting video games, movies and board games!
Enjoying my '11 WRX, so sexy...