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
- Make sure the model is the proper type in the cshtml page. ie: @model QRCodeG
 - Make sure the variable 's' actually has something in it
 - 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)
 加载中,请稍侯......
      
精彩评论