我将模型切回了一个领域://模型public class LetterViewModel{ public string LetterText;}//控制器public ActionResult Index(){ var model = new LetterViewModel(); model.LetterText = "Anything"; return View(model);}[HttpPost]public ActionResult Index(LetterViewModel model){ //model.LetterText == null return View(model);}//视图@model Test.Models.LetterViewModel@{ Layout = "~/Views/Shared/_Layout.cshtml"; ViewBag.Title = "Create a Letter";}@using (Html.BeginForm()){ <div id="Bottom"> @Html.TextAreaFor(m => m.LetterText) <input type="submit" value="Ok" class="btn btn-default" /> </div>}当我在开发工具中检查“网络”选项卡时,它显示输入的值已包含在请求中。但是,当HttpPost控制器被激发时,该字段为空。
3 回答
largeQ
TA贡献2039条经验 获得超7个赞
您需要在参数之前添加[FromBody]到操作
[HttpPost]
public ActionResult Index([FromBody]LetterViewModel model)
{
//model.LetterText == null
return View(model);
}
- 3 回答
- 0 关注
- 483 浏览
添加回答
举报
0/150
提交
取消