从Javascript文件访问MVC的模型属性

时间:2017-05-10 09:13:00

标签: javascript c# jquery model asp.net-mvc-5

我有以下模型,它包含在我想要的视图模型中 将MaximumDaysAheadBookable属性传递给datepicker函数

public class SessionObject
{    
    public int MaximumNumberOfRooms { get; set; }
    public int MaximumNumberOfAdultsPerRoom { get; set; }
    public int MaximumNumberOfChildrenPerRoom { get; set; }
    public int MaximumDaysAheadBookable { get; set; }
    public int MaximumDaysBetweenCheckinCheckout { get; set; }
}

如何从Javascript.js文件访问上述属性之一?然后将它传递给datepicker函数:

$('document').ready(function () {
   $("#Arrival").datepicker({
        minDate: 0,
        maxDate:MaximumDaysAheadBookable , ////here i want to pass model value 
        dateFormat: 'dd/mm/yy',
        showOn: "button",
        buttonImage: "img/ui_cal_icon.gif",
        buttonImageOnly: true,
        buttonText: "Select date",

    });
 });

1 个答案:

答案 0 :(得分:0)

在外部js文件中,您需要将数据作为参数传递。