亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我發回到控制器時,模型的所有值都為空

當我發回到控制器時,模型的所有值都為空

翻翻過去那場雪 2019-12-06 11:03:41
我將模型切回了一個領域://模型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條經驗 獲得超8個贊

您需要在參數之前添加[FromBody]到操作


[HttpPost]

public ActionResult Index([FromBody]LetterViewModel model)

    //model.LetterText == null

    return View(model);

}


查看完整回答
反對 回復 2019-12-06
  • 3 回答
  • 0 關注
  • 521 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號