有没有办法在 JavaScript 中访问特定类名下的 html 元素?
她的就是我目前所拥有的:
部分的:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Student.Models.vwStudent>>" %>
<table>
<tr>
<th>
Student ID
</th>
<th>
Past Due Amount
</th>
<th>
Past Due Days
</th>
</tr>
<% if (Model != null)
foreach (var item in Model) { %>
<tr>
<td class="StudentInv">
<%=Html.TextBox("StudentID",item.StudentID) %>
</td>
<td class="StudentInv">
<%=Html.TextBox("PastDueAmount",item.PastDueAmount) %>
</td>
<td class="StudentInv">
<%=Html.TextBox("PastDueDays",item.PastDueDays) %>
</td>
</tr>
<% } %>
掌握:
<div>
<% using(Html.BeginForm("SaveStudentInvoice", "StudentInvoice")) %>
<% { %>
<div>
<% Html.RenderPartial("DisplayStudentInvoiceList"); %>
</div>
<% } %>
<br/>
<input type="button" id="Submit" name="Submit" value="Submit" />
</div>
JavaScript:
$('#Submit').click(function () {
var link = '/StudentInvoice/SaveStudentInvoice';
$.ajax({
type: 'POST',
url: link,
data: { SaveStudent: $(".StudentInv").val()
},
dataType: 'json',
success: function (result) {
alert("Success")
},
error: function (result) {
alert("Failed")
}
});
});
控制器:
[HttpPost()]
public ActionResult SaveStudentInvoice(string SaveStudent)
{
/// Parse SaveStudent String and rerform some Action
return View();
}