0
我正在尝试使用User.Identity.Name用户名编辑客户。MVC3使用用户名编辑客户
我不知道如何写在控制器的条件。
看起来很简单。你可以帮帮我吗?谢谢。
这是我的编码。
[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的。查询到Models.Customer。这是什么意思? –
wholee1
2012-04-11 14:20:10
@ wholee1:你不明白哪部分错误信息? – SLaks 2012-04-11 14:21:11
Oh..when我把FirstOrDefault(),它的作品。谢谢! – wholee1 2012-04-11 14:23:33