无法将javascript值与模型值分配或比较 [英] cannot assign or compare javascript value with model values

查看:49
本文介绍了无法将javascript值与模型值分配或比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在MVC应用程序中使用JQuery Grid。我不能将javascript值与模型值分配或比较,以下是与之相关的代码。



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.    }



以下是我得到的错误:

第6行:名称val在当前上下文中不存在。

line8:由于''System.Web.WebPages.SectionWriter''返回void,因此返回关键字不能是
然后是一个对象表达。



请帮我解决这个问题。

对不起,如果我的英语很差。

先谢谢。



问候,

Rohith。


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.

推荐答案

您试图在客户端代码旁边运行服务器端代码,这将无法工作



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


这篇关于无法将javascript值与模型值分配或比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆