私はUser.Identity.Nameを使用しているユーザー名で顧客を編集しようとしています。MVC3ユーザー名を編集する(
コントローラのWhere条件を書き込む方法がわかりません。
これは簡単です。私たちを手伝ってくれますか?ありがとう。
ここに私のコーディングがあります。
[Authorize]
public ActionResult Edit()
{
//the username gets username through User.Identity.Name.
string username = User.Identity.Name;
//How can I write below coding?
//In DB, it has userName field.
Customer customer = db.Customer.Where(userName = username);
return View(customer);
}
[HttpPost]
public ActionResult Edit(Customer customer)
{
if (ModelState.IsValid)
{
db.Entry(customer).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(customer);
}
よりもリターンは多くの場合、それは「暗黙的にタイプを変換することができないと言う例外をスローSystem.Linqの.IqueryableをModels.Customerに追加します。どういう意味ですか? –
wholee1
@ wholee1:エラーメッセージのどの部分を理解していませんか? – SLaks
Oh .. FirstOrDefault()を置くと動作します。ありがとう! – wholee1