我需要從視圖到控制器傳遞這個對象:通行證對象到控制器MVC 5
public class QuoteVehicle
{
[DisplayName("Quote Vehicle ID")]
public int QuoteVehicleID { get; set; }
[DisplayName("Quote ID")]
public int QuoteID { get; set; }
[DisplayName("Model Year")]
public string ModelYear { get; set; }
//etc...
}
如果我在控制器中設置的值,它們被傳遞給圖;但如果我設置或更改視圖中的值並將其傳回......它會到達那裏,但值爲空。
我使用這個Ajax.BeginForm:
@Using (Ajax.BeginForm("GetQuote", "Quote",
New With {.QuoteVehicle = JsonConvert.SerializeObject(Model.QuoteVehicle)},
New AjaxOptions() With {
.UpdateTargetId = "PriceOptionsPanel",
.HttpMethod = "GET",
.OnComplete = "SetDatePickers",
.InsertionMode = InsertionMode.Replace,
.LoadingElementId = "loader"
}
))
我的屬性被綁定爲這種形式裏面:
@Html.TextBoxFor(Function(model) model.QuoteVehicle.Make, New With {.class = "form-control", .readonly = "readonly"})
,並在我的控制器:
Function GetQuote(QuoteVehicle As String) As ActionResult
Dim _quoteVehicle = JsonConvert.DeserializeObject(Of QuoteVehicle)(QuoteVehicle)
Return View(etc.)
End Function
我我也試過<HttpPost>
和.HttpMenthod = "POST"
,但那也沒有效果。
愛知道爲什麼他們沒有被設置...
這個模型看起來是這樣的:
Public Class MenuOptionsModel
Public Property VIN() As String
Public Property QuoteVehicle() As QuoteVehicle
Public Property IsDecoded As Boolean
Public Property IsNew As Boolean = False
Public Property Is30Day As Boolean?
Public Property IsUnderWarranty As Boolean?
etc...
End Class
性能不在一個對象,只是類型(即布爾?字符串)綁定很好,但對象內的屬性不。
你爲什麼想回來後正好你剛剛從服務器發送的同一個對象? –
爲什麼我不會?該對象在模型中...我需要用視圖中的數據填充該對象 - 我還會如何傳遞該信息? 20個獨立的領域? –
我不認爲你明白 - 你在服務器上序列化模型,發送給客戶端,併發回完全相同的模型,而不是編輯的任何東西。刪除BeginForm()的第三個參數並改變方法參數爲你的模型,而不是字符串 –