javascript - 如何从 MVC4 中的 Javascript 检查 View 模型中的模型值

标签 javascript asp.net-mvc asp.net-mvc-4

我想使用 mvc4 检查我的 JavaScript View 模型中的模型值是 NULL 还是 NOT NULL。

我该如何检查?

如何在 View 模型中使用 JavaScript 从我的模型中获取值?

最佳答案

可能有两种方式

首先

@{
    string property = "";

    property = Model.Property == null ? "null value" : "value";
    // OR another comparison strategy
    ...
}

<script type="javascript">
   var property = @(property);
</script>

第二个

<script type="javascript">
  var property = @(Model.Property == null ? "null value" : "value");
</script>

关于javascript - 如何从 MVC4 中的 Javascript 检查 View 模型中的模型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16708643/

相关文章:

asp.net - 部署错误 : Could not load file or assembly 'Microsoft.Owin' or one of its dependencies

c# - Azure ACS 凭据困惑

javascript - 用 jest 测试 React 中的异步方法

javascript - AngularJS $location 历史堆栈

javascript - 获取 <section> 标签的内容(包括 html 标签)并将其存储在变量中

c# - 如何全局访问当前的HttpRequestMessage对象?

asp.net-mvc-4 - 没有 JS 框架的 MVC 4 SPA?

javascript - 倒计时按钮 angularjs

c# - 将 DataTable 从 View 传递到新的 Controller 方法

asp.net - 使用 HEAD 或 OPTIONS 动词代替 POST 的登录表单