开发者

How to display info in view into if statement?

In constructor of class ModelError all is good in controller

public ActionResult ModeError()
        {
            return View("ModeError", new Models.ModeErrorInfo(this.Url.RequestContext.RouteData.Values));
        }

in view

<% 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.ParametrTy开发者_如何学Cpe, 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

    }

But i give empty view after executing! How i can dispaly this info?


It looks like you're not using Html.DisplayText() properly. Have a look at the documentation, and an example. This function doesn't just render stuff to the page, it operates in a special way.

For testing, why not just remove the calls to Html.DisplayText() and instead just write the content out using <%= Model.ParameterType %> ? That'll give you a clue as to whether your model contains valid information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜