MVC局部视图中的问题 [英] Issue in MVC partial view

查看:164
本文介绍了MVC局部视图中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手。我正在研究一个示例项目。请参阅我的下面的场景并为我提供解决方案。



在我的项目中,我有两种类型pf login。在First类型中,我有以下菜单。

主页,新问题,阅读现有问题,回答问题,关于我们



在下次登录时,我有以上几个细节,例如,我有以下选项

主页,新问题,关于我们



我是否必须使用不同的布局页面或以任何方式使用相同的布局页面进行登录。



我试过在布局页面中有部分视图,但我得到一个错误说有一个模块XXX和部分视图有模块YYY。请看下面的错误。



传入字典的模型项是'MVCTMS.Models.EnrollmentInfo'类型,但是这个字典需要一个'MVCTMS.Models.EnrollmentTablink'类型的模型项目。



请帮帮我。



谢谢

Balaji.N

Hi I am new to MVC. I am working on a sample project. Please see my below scenario and provide me a solution.

In my project I have two types pf login. In First type I have the following menu.
Home, New Questions, Read Existing Questions, Answer Questions, About US

In the next Login I have few of the above details like, I have below options
Home, New Questions, About US

Do i have to use different layout page or is any way to use same layout page for both the login.

I tried by having the partial view in layout page, But I got an error says that there is a module XXX and partial view has module YYY. Please see the below error.

The model item passed into the dictionary is of type 'MVCTMS.Models.EnrollmentInfo', but this dictionary requires a model item of type 'MVCTMS.Models.EnrollmentTablink'.

please help me with this.

Thank You
Balaji.N

推荐答案

我通常只使用一个布局文件。



您发布的错误意味着您的视图需要一个类型为EnrollmentTablink的模型,但您要从您调用视图的任何地方传递一个类型为EnrollmentInfo的模型。



我不知道你的模特是怎样的,但首先,你可以尝试使用相同的型号。



您可以尝试阅读本文以获得更好的效果理解ASP.NET MVC中的模型和视图 [ ^ ]
I usually use only one layout file.

The error you posted means that your view is expecting a model of type EnrollmentTablink but you are passing a model of type EnrollmentInfo from wherever you are calling your view.

I don't know how your models look like, but to start with, you could try using the same models.

You can try reading this to get a better understanding of models and views in ASP.NET MVC[^]


我认为您使用EnrollmentTablink模型创建强类型局部视图,您需要在EnrollmentInfo模型中创建EnrollmentTablink模型的对象,现在您调用部分视图,如

I think you create strongly type partial view with EnrollmentTablink Model, you need to create object of EnrollmentTablink Model in EnrollmentInfo Model and now you call partial view like
@Html.Partial("PartialName",model.enrollmentTablink)



你需要




you need to

Public Class EnrollmentInfo()
{
  Public EnrollmentTablink enrollmentTablink{get;set}
  Public EnrollmentInfo
   {
     enrollmentTablink= new enrollmentTablink();
   }
}


这篇关于MVC局部视图中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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