我正在尝试保存数据库的一些更改。该视图有一个模型,应该能够进行更改并保存它们。但是,当我提交表格时,邮政方法中的ContactInfo参数不是null,但所有属性均为
。我将MVC5与剃须刀一起使用。该脚本是单独的.ts-file
在控制器中:
[HttpPost]
public bool SaveInfoChanges(ContactInfo editedContactInfo)
{
// Save data
return true;
}
脚本:
export function saveInfoChanges() {
$("#EditContactInfoForm").submit();
};
html:
@if (true)
{
@using (Html.BeginForm("SaveInfoChanges", "ContactInfoBox", FormMethod.Post, new { id = "EditContactInfoForm" }))
}
<table>
@Html.HiddenFor(model => model.Name)
@Html.HiddenFor(model => model.Address1)
@Html.HiddenFor(model => model.Address2)
@Html.HiddenFor(model => model.ZipAndCity)
@Html.HiddenFor(model => model.Country)
<tr>
<td>test</td>
<td>
@Html.TextBoxFor(model => model.Address3, new { id = "ContactTypeInput", placeholder = "", style = "width:300px" })
</td>
</tr>
</table>
}
}
模型:
public class ContactInfo
{
public string ContactInfoBoxHeaderText { get; set; }
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string ZipAndCity { get; set; }
public string Country { get; set; }
}
我想不出要提供的更多相关信息,但请不要犹豫。预先感谢!
删除@if解决了问题。我只需要找到另一种隐藏/显示元素的方法。