单击保存(更新)我的表单后出现此错误:
由于一个或多个外键属性不可为空,因此无法更改关系.当对关系进行更改时,相关的外键属性将设置为空值.如果外键不支持空值,则必须定义新关系,必须为外键属性分配另一个非空值,或者必须删除不相关的对象.
这是我的控制器(案例"保存"在swich couse问题):
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(UserModel userModel, string act = null, int idx = 0)
{
using (var dbContext = new userDbEntities())
{
if (userModel.User == null)
{
userModel.User = new UsersTable();
}
var newUser = userModel.User.userID == 0;
userModel.CustomTypes = dbContext.CustomTypes.ToList();
switch (act)
{
case "addcustom":
userModel.User.CustomerTables.Add(new CustomerTable
{
CustomType = new CustomType(),
UsersTable = userModel.User
});
break;
case "deletecustom":
userModel.User.CustomerTables.RemoveAt(idx);
break;
case "save":
foreach (var customer in userModel.User.CustomerTables)
{
customer.CustomType = dbContext.CustomTypes.Find(customer.CustomType.Id_NewCustomerType);
}
var dbUser …Run Code Online (Sandbox Code Playgroud) 如何在ActionLink按钮中放置图像而不是文本:
@Html.ActionLink("Edit-link", "Edit", new { id=use.userID })
Run Code Online (Sandbox Code Playgroud)
那么如何将文本"编辑链接"更改为图像?
谢谢你的想法.