为什么不使用 jQuery post 值动态创建文本框到控制器中的 post 方法?
jQuery代码如下:
$(document).ready(function () {
var counter = 0;
var curContactCount = $("#contactcount").val();
$("#addContactButton").click(function () {
if (parseInt(counter) + parseInt(curContactCount) >= 50) {
alert("Only 50 Contacts allowed");
return false;
}
var firstNameStr = 'NewContactList[' + counter + '].FirstName';
var firstNameId = firstNameStr.replace("[", "_").replace("]", "_").replace(".", "_");
var newTextBoxDiv1 = $(document.createElement('div')).attr("id", 'NewContactGroup');
newTextBoxDiv1.html(
' <div class="column-margin-20t20b">' +
' <div class="box">' +
' <div class="left">' +
'<label for="' + firstNameId + '">First Name</label>' +
' </div>' +
' <div class="right">' +
' <input type="text" name="' + firstNameStr + '" id="' + firstNameId + '" value=""></input>' +
' </div>' +
' </div>' +
' </div>'
);
newTextBoxDiv1.appendTo("#mainDivNewClient");
counter++;
});
});
控制器代码:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddNewClient(ClientViewModel clientToAdd, System.Collections.Generic.Dictionary<string, string> qString)
{
try
{
if (ModelState.IsValid)..........
在 clientToAdd 中,我将 NewContactList 设为 nulll。为什么?