访问javascript中的模型值 [英] access model values in javascript
本文介绍了访问javascript中的模型值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下型号:
Hi,
I have the following model:
public class MyModel
{
public string UserName { get; set;}
public bool IsAdmin { get; set;}
}
在我的控制器中:< br $> b $ b
In my controller:
model.IsAdmin = false;
model.UserName = "localhost";
我需要在javascript中获取这些值。我不允许使用隐藏变量。还有其他方法吗?
I need to get these values in javascript. I am not allowed to use hidden variables. Is there any other way?
推荐答案
试试这样
try like this
<script type="text/javascript">
//take the model value from javascript
var getModelData="@model.IsAdmin";
</script>
或
你可以在javascript中获取所有模型值,如下所示
or
You can take all the model values in javascript like below
<script type="text/javascript">
var model = @Html.Raw(Json.Encode(Model))
</script>
希望这有助于
Hope this helps
这篇关于访问javascript中的模型值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文