2015-10-20 41 views
0

我在嘗試更新模型屬性值,但在httpost中未反映輸入的新值,顯示原始值。 感謝您的幫助。MVC6輸入asp-for not change模型屬性值

<div class="row row-padding"> 
<section class="form-field"> 
    <input asp-for="bidDataProcess.MaxBidPosted" type="number" class="form-control" /> 
    <form asp-controller="Item" asp-action="PlaceBid" asp-route-ItemId="@Model.itemDescription.ItemId" asp-route-MaxBid="@Model.bidDataProcess.MaxBidPosted" method="post" class="clearfix"> 
     <input id="PlaceBid" type="submit" style="background-color:blue;color:white; font-weight:bold;width:50%" class="form-control text-center" value="Place Bid" /> 
    </form> 
</section> 


[HttpPost] 
public ActionResult PlaceBid(int ItemId, decimal MaxBid) 
{ 
// Maxbid resturns the original value not the new value entered. 
decimal maxBid = MaxBid; 
return View(); 
} 
+0

是我不是因爲輸入標籤超出了您的表單打開和關閉標籤? – firste

回答

0
  • 你不需要複製文本的形式要素投入和routevalues。
  • 你MaxBidPosted輸入需要表單標籤內,否則MaxBid控制器將爲零
  • 您輸入的域名(MaxBidPosted)需要你的控制器參數(MaxBid)否則MaxBid匹配的控制器將是零

CSHTML:

<div class="row row-padding"> 
     <section class="form-field"> 
      <form asp-controller="Item" asp-action="PlaceBid" asp-route-ItemId="@Model.ItemId" method="post" class="clearfix"> 
       <input asp-for="MaxBidPosted" type="number" class="form-control" /> 
       <input id="PlaceBid" type="submit" style="background-color:blue;color:white; font-weight:bold;width:50%" class="form-control text-center" value="Place Bid" /> 
      </form> 
     </section> 
    </div> 

控制器:

[HttpPost] 
    public ActionResult Index(int ItemId, decimal MaxBidPosted) 
    { 
     decimal maxBid = MaxBidPosted; 
     return View(); 
    }