错误:文件中只允许一个“模型”语句。 [英] Error : Only one 'model' statement is allowed in a file.

查看:436
本文介绍了错误:文件中只允许一个“模型”语句。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Only one 'model' statement is allowed in a file.


Source Error:

Line 4:      ViewBag.Title = "Create"; Line 5:  } Line 6:  @model int Line 7:   Line 8:  @{

Source File: /Views/tblhotelmasters/Create.cshtml Line: 6



@model WebPortal_Planmiles.Models.Data.tblhotelmaster
@{
ViewBag.Title = "Create";
}
@model int
@{
var chk = "checked";
var checked1 = Model == 1 ? chk : null;
var checked2 = Model == 2 ? chk : null;
var checked3 = Model == 3 ? chk : null;
var checked4 = Model == 4 ? chk : null;
var checked5 = Model == 5 ? chk : null;
var htmlField = ViewData.TemplateInfo.HtmlFieldPrefix;
}

推荐答案

你有两个 @model 陈述



You have two "@model" statements

@model WebPortal_Planmiles.Models.Data.tblhotelmaster
@model int





你只能拥有一个,就像错误消息告诉你,所以删除一个。我们不知道哪一个是正确的,你必须解决这个问题,但看起来int可能与其他视图代码一致。



you can only have one, exactly as the error message is telling you, so remove one. We don't know which one is the correct one, you'll have to work that out, but it looks like "int" might be correct from the rest of your view code.


错误不可能更清楚! @model 可以在你的视图中找到两次。



祝你好运!
The error could not be more clear! @model can be found twice in your view.

Good luck!


要添加到基本上正确的其他解决方案,如果您确实需要来自两个模型的信息(int和WebPortal_Planmiles.Models.Data.tblhotelmaster),请考虑:



a)将int移动到viewbag或tempdata



b)构建一个包含WebPortal_Planmiles.Models.Data.tblhotelmaster 一个额外的整数。



无论哪种方式都适合你。
To add to the other solutions, which are fundamentally correct, if you do indeed want the information from both models (the int and the WebPortal_Planmiles.Models.Data.tblhotelmaster) consider either:

a) Move the int into the viewbag or tempdata

b) Constructing a view model that contains both the WebPortal_Planmiles.Models.Data.tblhotelmaster and an additional integer.

Either way should work for you.


这篇关于错误:文件中只允许一个“模型”语句。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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