![](/img/trans.png)
[英]ASP.NET MVC3 model binder data is invalid when a getter is used against the collection
[英]Bind Data Of a span to database with ASP MVC,Uses Model Binder
我是Asp.net MVC的新手
我需要一些建議,以了解如何制作一個計數器,然后將其值提供給粘結劑模型。
我有兩個modal
頁面。在第一個頁面中,我有一個計數器供用戶選擇其請求編號,如下所示:當用戶單擊加號圖標時,編號By Javascript
更改
當用戶單擊next按鈕時,將顯示下一個模式頁面,我已在其中selecteddate
和使用javascript number of travelers
。 以及我希望模型活頁夾成為其對象的形式。
這是我的下一個模態頁面的摘要
<p>
<span id="selecteddate"></span>
<span id="selectedcount"></span>
<span id="selectedprice"></span>
</p>
這是javascript:
$(".nextbtn").click(function () {
$("#selecteddate").html("Selected Date is : "+$("#showdate").html());
$("#selectedprice").html("Total Price is : " + $("#tpriceforall").html());
$("#selectedcount").html($("#shownum").html());
});
它可以正常工作。
在下一個模態頁面中我也有一個表單。 我想將用戶的輸入數據傳遞給數據庫+ java script set it each time
span
#selectedcount
中可用的數字。
正如我想使用ModelBinder
,有一個輸入將被隱藏。 只是為了傳遞數據。 這是我的請求模型的TravellersCount的輸入
<div class="form-group">
@Html.LabelFor(model => model.Request.TravelersCount, htmlAttributes: new {@class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Request.TravelersCount, new { htmlAttributes = new { @class = "form-control", @*@Value=?????*@ } })
@Html.ValidationMessageFor(model => model.Request.TravelersCount, "", new { @class = "text-danger" })
</div>
</div>
我應該在EditorFor
為Value
寫什么?
或者,如果這種方式是完全不規則的,請給我建議一個新方法。 非常感謝您的幫助。 謝謝
您的EditorFor()
方法創建一個帶有id="Request_TravelersCount"
的輸入。
要在單擊按鈕時更新其value
,可以使用
$(".nextbtn").click(function () {
$("#selecteddate").html("Selected Date is : "+$("#showdate").html());
$("#selectedprice").html("Total Price is : " + $("#tpriceforall").html());
var num = $("#shownum").html();
$("#selectedcount").html(num);
$('#Request_TravelersCount').val(num);
});
旁注:您不應嘗試在HtmlHelper
方法中設置value屬性(該方法將考慮ModelState
值來設置正確的值)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.