Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript jQuery Model
Hi ,
 
I'm using a JQuery Grid in MVC Application. I cannot assign or compare javascript value with model values the following is the code related to it.
 
1. function (value) {
2.        var  val=value;
3.        @foreach (var item in Model.ToList())
4.         {
5.       //val=@item.FKAlbumId
6.             if (@item.FKAlbumId ==Convert.ToInt32(val.ToString()))
7.             {
8.                    return @item.Album.Title;
9.             }
10.    }
The following are the errors I get:
line 6: the name val doesn't exist in the current context.
line8: Since 'System.Web.WebPages.SectionWriter' returns void, a return keyword must not be
followed by an object expression.
 
Please help me in sorting out this issue.
Sorry if my english is poor.
Thanks in Advance.
 
With Regards,
Rohith.
Posted 4-Apr-13 21:11pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are trying to run server-side code alongside client-side code this will not work
 
/*this is client-side code*/
 function (value) {
  var  val=value;
/*this is client-side code*/
 
/*this is server-side code - it will run when page is being rendered but will not exists in the client browser */
  @foreach (var item in Model.ToList())
   {
       //val=@item.FKAlbumId
        /* val still not exists and will only do when javascript code be evaluated in the browser*/
       if (@item.FKAlbumId == Convert.ToInt32(val.ToString()))
       {
              return @item.Album.Title;
       }
    }
/*this is server-side code*/
  }
 
and give your function a name if you want to call it.
 
Hope it helps.
And sorry, my english is bad too
  Permalink  
Comments
Rohith Reddy Vadiyala at 6-Apr-13 0:38am
   
Thanks @Moykn. Thanks for your suggestion..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100