我在MVC新的和我的工作項目中,我有一個GridView顯示數據,當我點擊Edit
特定行變得textboxes
和Edit
成爲Save
,我編輯數據,然後點擊Save
,控制權就在jQuery的功能,編輯的行數據發送到使用AJAX控制方法,我把警報看到塔的數據,給了我這個字符串檢索信息
和空是要我控制器方法和我得到一個異常
我的jQuery/Ajax代碼:
<script type="text/javascript">
$(document).ready(function() {
function toggleEditability() {
$(this).closest('tr')
.find('a.Edit, a.Save, .displayText, input[type=text]')
.toggle();
}
$('a.Edit').click(toggleEditability);
$('a.Save').click(function() {;
toggleEditability.call(this);
var data = $(this).closest('tr').find('input').serialize();
alert(data);
$.ajax({
url: '@Url.Action("Edit", "Holiday")', // Url to send request to
data: data, // Send the data to the server
type: "Post", // Make it a POST request
dataType: "html", // Expect back HTML
//contentType: 'application/json; charset=utf-8',
success: function (html) {
alert(html);
console.log(html);
},
error: function() {
alert("error");
}
});
});
});
</script>
CHTML代碼:
<div id="details">
<table>
<tr>
@*<th>
@Html.Label("ID")
</th>*@
<th>
@Html.Label("Name")
</th>
<th>
@Html.Label("Description")
</th>
<th>
@Html.Label("Date")
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
if (Convert.ToDateTime(item.Holiday_date).Year.ToString() == DateTime.Now.Year.ToString())
{
<tr>
@Html.HiddenFor(modelItem => item.Holiday_Id)
@*<td>
@Html.DisplayFor(modelItem => item.Holiday_Id)
@Html.HiddenFor(modelItem => item.Holiday_Id)
</td>*@
<td>
<div class="HolidayName">
@Html.TextBoxFor(modelItem => item.Holiday_Name, new { id = "txtname", name="HolidayName", style = "display: none; width:170px; height:15px" })
</div>
<div class="displaytext">
@Html.DisplayFor(modelItem => item.Holiday_Name)
</div>
</td>
<td>
<div class="HolidayDescription">
@Html.TextBoxFor(modelItem => item.Holiday_Description, new { id = "txtdesc", name="HolidayDescription", style = "display: none; width:170px; height:15px" })
</div>
<div class="displaytext">
@Html.DisplayFor(modelItem => item.Holiday_Description)
</div>
</td>
<td>
<div class="HolidayDate">
@Html.TextBoxFor(modelItem => item.Holiday_date, new { id = "txtdate", name="HolidayDate", style = "display: none; width:170px; height:15px" })
</div>
<div class="displaytext">
@Html.DisplayFor(modelItem => item.Holiday_date)
</div>
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Holiday_Id }, new { @class = "Edit", Href="#" })
@Html.ActionLink("Save", "Save", new { id = item.Holiday_Id}, new { @class = "Save", Href = "#", style = "display:none" }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Holiday_Id }, new { @class = "lnkDelete" })
@Html.ActionLink("Cancel", "Cancel", new { id = item.Holiday_Id}, new { @class = "Cancel", Href = "#", style = "display:none" })
</td>
</tr>
}
}
</table>
</div>
和我的控制器方法的代碼是:
[HttpGet]
public ActionResult Edit(int id = 0)
{
tbl_HolidayList tbl_holidaylist = db.tbl_HolidayList.Find(id);
if (tbl_holidaylist == null)
{
return HttpNotFound();
}
return PartialView(tbl_holidaylist);
}
//
// POST: /Holiday/Edit/5
[HttpPost]
public ActionResult Edit(tbl_HolidayList tbl_holidaylist)
{
if (ModelState.IsValid)
{
db.Entry(tbl_holidaylist).State = EntityState.Modified;
db.SaveChanges();//save changes
TempData["Msg"] = "Data has been updated succeessfully";
return RedirectToAction("Index");
}
return PartialView(tbl_holidaylist);
}
我的問題是,我如何才能找回我從該字符串的具體信息在data
如此我的控制器方法可以得到這個參數?
可能重複(HTTP:// stackoverflow.com/questions/27806182/getting-multiple-textboxes-values-in-jquery-mvc) –
這個問題是不同的,這個問題是關於格式化字符串 –