.net 如何在if语句中显示视图中的信息?
在ModelError类的构造函数中,一切都很好 内部控制器.net 如何在if语句中显示视图中的信息?,.net,asp.net,asp.net-mvc,.net,Asp.net,Asp.net Mvc,在ModelError类的构造函数中,一切都很好 内部控制器 public ActionResult ModeError() { return View("ModeError", new Models.ModeErrorInfo(this.Url.RequestContext.RouteData.Values)); } 鉴于 <% if (this.Model.SPECIALTY == null || string.IsNullOr
public ActionResult ModeError()
{
return View("ModeError", new Models.ModeErrorInfo(this.Url.RequestContext.RouteData.Values));
}
鉴于
<% if (this.Model.SPECIALTY == null || string.IsNullOrEmpty(this.Model.SPECIALTY))
{
Html.DisplayText(String.Format("{0} {1} is missing", Model.ParametrType, Model.Speciality));
} %>
<% else
{
Html.DisplayText(String.Format("{0} {1} {2}", Model.ParametrType, Model.Speciality, Model.SPECIALTY));
} %>
public class ModeErrorInfo
{
#region Constants
public readonly string Session = "SESS";
public readonly string Mode = "MODE";
public readonly string App = "APP";
public readonly string Usertype = "USERTYPE";
public readonly string Speciality = "SPECIALTY";
public readonly string ParametrType = "URL";
#endregion
#region Public Properties
public string SESS { get; set; }
public string APP { get; set; }
public string USERTYPE { get; set; }
public string SPECIALTY { get; set; }
public string MODE { get; set; }
#endregion
#region Constructors
public ModeErrorInfo(RouteValueDictionary values)
{
if (values != null)
{
this.APP = (string)values[this.App];
this.SESS = (string)values[this.Session];
this.SPECIALTY = (string)values[this.Speciality];
this.USERTYPE = (string)values[this.Usertype];
this.MODE = (string)values[this.Mode];
}
}
#endregion
}
公共类ModeErrorInfo
{
#区域常数
公共只读字符串Session=“SESS”;
公共只读字符串Mode=“Mode”;
公共只读字符串App=“App”;
公共只读字符串Usertype=“Usertype”;
公共只读字符串Speciality=“Speciality”;
公共只读字符串参数type=“URL”;
#端区
#区域公共财产
公共字符串SESS{get;set;}
公共字符串APP{get;set;}
公共字符串用户类型{get;set;}
公共字符串专用项{get;set;}
公共字符串模式{get;set;}
#端区
#区域构造函数
公共模式错误信息(RouteValueDictionary值)
{
如果(值!=null)
{
this.APP=(字符串)值[this.APP];
this.SESS=(字符串)值[this.Session];
this.Speciality=(字符串)值[this.Speciality];
this.USERTYPE=(字符串)值[this.USERTYPE];
this.MODE=(字符串)值[this.MODE];
}
}
#端区
}
但执行后我给出空视图!如何显示此信息?看起来您没有正确使用
Html.DisplayText()
。看一看,然后看一眼。这个函数不仅仅向页面呈现内容,它还以一种特殊的方式运行
对于测试,为什么不删除对
Html.DisplayText()
的调用,而只使用
写出内容呢?这将为您的模型是否包含有效信息提供线索。您在问什么?你看到的问题是什么?