Sto provando a pubblicare un array JSON su un controller MVC. Ma qualunque cosa provi, tutto è 0 o null.Post array JSON al controller mvc
Ho questa tabella che contiene caselle di testo. Ho bisogno di tutte quelle caselle di testo è ID e valore come un oggetto.
Questo è il mio Javascript:
$(document).ready(function() {
$('#submitTest').click(function (e) {
var $form = $('form');
var trans = new Array();
var parameters = {
TransIDs: $("#TransID").val(),
ItemIDs: $("#ItemID").val(),
TypeIDs: $("#TypeID").val(),
};
trans.push(parameters);
if ($form.valid()) {
$.ajax(
{
url: $form.attr('action'),
type: $form.attr('method'),
data: JSON.stringify(parameters),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
$('#result').text(result.redirectTo)
if (result.Success == true) {
return fase;
}
else {
$('#Error').html(result.Html);
}
},
error: function (request) { alert(request.statusText) }
});
}
e.preventDefault();
return false;
});
});
Questo è il mio codice della vista:
<table>
<tr>
<th>trans</th>
<th>Item</th>
<th>Type</th>
</tr>
@foreach (var t in Model.Types.ToList())
{
{
<tr>
<td>
<input type="hidden" value="@t.TransID" id="TransID" />
<input type="hidden" value="@t.ItemID" id="ItemID" />
<input type="hidden" value="@t.TypeID" id="TypeID" />
</td>
</tr>
}
}
</table>
Questo è il controller im cercando di ricevere i dati per:
[HttpPost]
public ActionResult Update(CustomTypeModel ctm)
{
return RedirectToAction("Index");
}
Cosa am Sto sbagliando?
Mostra come è il tuo 'CustomTypeModel'. –
quale versione di mvc stai usando? –
Sembra che manchino gli attributi 'name' con il nome delle proprietà che si sta provando a POST. E puoi pubblicare i dati reali che stai postando? La richiesta POST effettiva? – rae1