我在mu模型中有一個屬性,其中我不希望用戶在編輯操作期間訪問其值。 如果我沒有在編輯視圖中包含它,它會得到一個空值。如果我將它作爲隱藏值包含在內,用戶可以通過瀏覽器中的「查看源代碼」選項查看它的值。忽略編輯視圖中的一個字段asp.net mvc 3
任何提示? 這裏是編輯動作
public ActionResult Edit()
{
Profile profile = null;
if (_db.Profiles.Count() > 0)
profile = _db.Profiles.Single(p => p.UserName == User.Identity.Name);
if (null == profile)
return RedirectToAction("Create");
else
return View(profile);
}
//
// POST: /Profile/Edit/5
[HttpPost]
public ActionResult Edit(Profile newProfile)
{
try
{
TryUpdateModel(newProfile);
if (ModelState.IsValid)
{
_db.Entry(newProfile).State = EntityState.Modified;
_db.SaveChanges();
if (newProfile.Confirmed)
{
return RedirectToAction("Index", "Home");
}
else
return RedirectToAction("Confirm");
}
else
return View(newProfile);
}
catch
{
return View();
}
}
你爲什麼不在你的[post]中賦值? – ShaneKm
這是我的情景:當用戶在網站註冊時,我向他的手機發送一個4位數的驗證號碼。我將此驗證號碼包含在用戶的個人資料模型中。當用戶想要編輯他的個人資料時,我必須隱藏這個字段。 –