将值从模型传递到javascript [英] Passing value from model to javascript

查看:68
本文介绍了将值从模型传递到javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想剪切一个日历模板,我有一个模型: -



  public   class  TimeSlotModel 
{
public long ID { get ; set ; }
public DayOfWeek DayOfWeek { get ; set ; }
public string StartHour { get ; set ; }
public string EndHour { get ; set ; }
}





这些字段保存在db中,现在我想在calendar.js中使用这些条目,

所以我如何在javascript模板中使用模型值。



谢谢

解决方案

< blockquote>

如果你想在javascript中使用模型值,那么你需要访问这样的模型值



var modelJSValue = '@ Model.Id';(Razor代码)或'<%:Model.Id%>'



现在你的modelJSValue将拥有属于的ID值你的模型。



更新的解决方案:

 < ;   script  >  
jQuery(document).ready(function() {
//启动布局和插件
App.init();
var modelJSValue ='@ Model.Id';
alert(modelJSValue); //确认并查看内容我们得到了这一点。
Calendar.init(modelJSValue); //将modelJSvalue传递给你的脚本
});
< / script >





注意:确保你也读取了js文件中的参数值。

希望这对你有所帮助。



问候,

RK


Hello,
I want to cutomize a calendar template and for which I have a model:--

public class TimeSlotModel
    {
        public long Id { get; set; }
        public DayOfWeek DayOfWeek { get; set; }
        public string StartHour { get; set; }
        public string EndHour { get; set; }
    }



these fields are save in db and now i want to use these entries in my calendar.js,
So how i use the model values in javascript template.

Thanks

解决方案

Hi,
If you want to use model value in javascript,then you need to access model value like this

var modelJSValue = '@Model.Id';(Razor code) or '<%: Model.Id %>'

Now your modelJSValue will have value of ID that belongs to your model.

Updated solution:

<script>
        jQuery(document).ready(function () {
            // initiate layout and plugins
            App.init();
            var modelJSValue = '@Model.Id';
alert(modelJSValue); //Confirm and see what we get at this point.
            Calendar.init(modelJSValue); //Pass modelJSvalue to your script
});
</script>



Note: Make sure you read the parameter value in your js file as well.
Hope this helps you a bit.

Regards,
RK


这篇关于将值从模型传递到javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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