Asp.Net MVC Model返回Null [英] Asp.Net MVC Model Return Null

查看:332
本文介绍了Asp.Net MVC Model返回Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是MVC的新手我的问题是,我的朋友已经开发了项目管理员方面,我应该开发网站



现在,我的结构看起来像



-MODEL

-CONTROLLER

-VIEW

--Areas

---管理员

---网页


现在
admin和web使用相同的模型和控制器管理工作正常,没有错误

但是例如,我在Web Areas中创建index.cshtml并且我写了这段代码



Hi,
I am newbie in MVC my problem is that, my friend has developed project admin side, and I should develop web side

Now, my structere look like

-MODEL
-CONTROLLER
-VIEW
--Areas
---Admin
---Web

now inde admin and web which use same model and controller admin works normal, there is no error
but for example, I create index.cshtml within Web Areas and I wrote this code

<table class="table">
    <tr>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.Label(item.TypeName)
        </td>
    </tr>
}

</table>





这是我的_UsersType部分视图cshtml我在索引中使用了这个部分但是模型返回null我的问题在哪里?



我的routeconfig看起来像是





this is my _UsersType partial view cshtml and I used this partial in index but always Model return null where is the my problem?

and also my routeconfig look like

routes.MapRoute(
               name: "AdminDefault",
               url: "Admin/{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
           ).DataTokens.Add("Area", "Admin");

           routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
               namespaces: new[] { "Otoneov2.Presentation.Mvc.Controllers" }
           ).DataTokens.Add("Area", "Web");

推荐答案

您发布的所有代码都与此问题无关。



什么是相关的是控制器中返回所需视图的代码。显然,您没有传递View正在查找的对象,或者您传递了一个您认为包含数据但实际上包含null的对象。
None of the code you posted has anything to do with the problem.

What is relevent is the code in the controller that is returning the View you want. Apparently, you didn't pass object that the View was looking for or you passed an object that you thought contained the data but in fact contains null.


这篇关于Asp.Net MVC Model返回Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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