我的视图模型中包含以下模型public class FloorPlanSettingsModel{ public int Id { get; set; } public int? MainFloorPlanId { get; set; } public string ImageDirectory { get; set; } public string ThumbnailDirectory { get; set; } public string IconsDirectory { get; set; }}如何从Javascript访问上述属性之一?我尝试了这个,但是我得到了“未定义”var floorplanSettings = "@Model.FloorPlanSettings";alert(floorplanSettings.IconsDirectory);
3 回答
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
您可以通过以下步骤将整个服务器端模型转换为Javascript对象:
var model = @Html.Raw(Json.Encode(Model));
在您的情况下,如果只需要FloorPlanSettings对象,则只需传递Encode方法that属性:
var floorplanSettings = @Html.Raw(Json.Encode(Model.FloorPlanSettings));
添加回答
举报
0/150
提交
取消