开发者

have problem with MVC, String not Showing in the Return View

in the Controller:

       public ActionResult Create()
            {
                int i = 0;
                string s = "";
                bool uniqu开发者_如何学Goe = false;

                while (!unique)
                {
                    s = GenerateCode(i);

                    var CheckURLs = from x in db.QRCodeGs
                            where x.QRCodeShortString == s
                            select new { ShortCode = x.QRCodeShortString};
                    if (CheckURLs.Count() == 0)
                    {
                        unique = true;
                    }
                    else
                    {
                        i++;
                    }
                }


        return View(new QRCodeG { QRCodeShortString = s, QRCodeGenDate =    DateTime.Today, LastEditDate = DateTime.Today, LastEditor = User.Identity.Name });

            //return View();
           } 

Create.cshtml page:

    <div class="editor-field">
        @Html.EditorFor(model => model.QRCodeShortString)
        @Html.ValidationMessageFor(model => model.QRCodeShortString) <br />(You make   choose your own string or use this dynamically generated one)
    </div>


Not sure exactly what the problem is, but here's a few things to check

  1. Make sure the model is the proper type in the cshtml page. ie: @model QRCodeG
  2. Make sure the variable 's' actually has something in it
  3. Check your css (editor-field class) to make sure you aren't hiding it by mistake.


the first thing I would suggest is to move where you declare the model you are passing to the view, do something like

var qrCodeG = new QRCodeG { QRCodeShortString = s, QRCodeGenDate =    DateTime.Today, LastEditDate = DateTime.Today, LastEditor = User.Identity.Name };
return qrCodeG;

then use the debugger to see if qrCodeG is being populated correctly.

if that works then try adding

<div> @model.QRCodeShortString </div>

to your view and see if that is outputting your data correctly

if that works look at what is going on in @Html.EditorFor(model => model.QRCodeShortString)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜