2 回答
TA贡献1824条经验 获得超8个赞
您需要创建一个 Edit 方法来处理 Post
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int? id, ExpensesViewModel vmodel)
{
... perform edit
}
TA贡献1757条经验 获得超8个赞
通过删除 viewmodel 参数并在函数中声明来解决此问题,谢谢
// GET: Expenses/Edit/5
public async Task<IActionResult> Edit(int? id)
//public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var expenses = await _context.Expenses.SingleOrDefaultAsync(m => m.Id == id);
//if (expenses == null)
//{
// return NotFound();
//}
//return View(expenses);
ExpensesViewModel vmodel = new ExpensesViewModel();
if (expenses == null)
{
return NotFound();
}
else
{
vmodel.Id = expenses.Id;
vmodel.Expense_Code = expenses.Expense_Code;
vmodel.Expense_Name = expenses.Expense_Name;
vmodel.Category = expenses.Category;
}
return View(vmodel);
}
- 2 回答
- 0 关注
- 195 浏览
添加回答
举报