Click here to Skip to main content
11,789,512 members (37,179 online)
Rate this: bad
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,
Posted 4-Apr-13 20:11pm

1 solution

Rate this: bad
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 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
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 954
1 Maciej Los 765
2 KrunalRohit 666
3 CPallini 606
4 Richard MacCutchan 420

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2015
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