如何在MVC2视图中包含UserControl和Model?
我有用于特定视图的用户控件和模型。用户控件工作正常,同时我尝试将单选按钮包含在与模型相同的视图上。我收到错误:“传递到字典中的模型项的类型为“System.Data.DataTable”,但该字典需要类型为“MyModelName”的模型项”。
那么你能帮助任何人吗?
谢谢, 莫罕
I have UserControl as well as Model for particular view. Usercontrol is working properly at the same time i try to include radiobutton on the same view with model. I am getting the Error:"The model item passed into the dictionary is of type 'System.Data.DataTable', but this dictionary requires a model item of type "MyModelName"".
So can you please help anyone.
thanks,
Mohan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异常消息的描述性很强,说明了一切。您的视图接受不同的模型,并且您将不同的模型传递给控制器中的该视图。
看看两个地方
,在你的控制器中,你会有类似
Edit 的东西,你可以使用 viewModel ,它可以包含视图所需的所有值,
现在在控制器中,你可以像这样填充你的 viewModel
,并且在你应该更新的视图中它接受 MyViewModel 类型
,然后您可以使用在视图中访问它们
The Exception Message is very descriptive and says it all. your view accepts a different model and you are passing different model to this view in controller.
Look at two places
and in your controller you would have something like
Edit you can use viewModel that can contain all values required by the view
now in controller you can populate your viewModel like
and in the view you should update it to accept MyViewModel type
and then you can access them in view using