MVC 專案。
這是我的搜索視圖。這將在用戶輸入他的手機號碼時顯示資訊。后面跟著js代碼。
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
Enter Your Mobile Number:<input id="txtMobileNumber" type="text" />
</div>
</div>
</nav>
<div>
<br />
<br />
<table class="table table-striped" id="tblCustomers" cellpadding="0" cellspacing="0">
<tr>
<th style="width: 90px">employee_name</th>
<th style="width: 120px">mobile_number</th>
<th style="width: 90px">service_plan</th>
<th style="width: 90px">usuge_limit</th>
</tr>
</table>
完成搜索的 Javascript 代碼:
$(function () {
$("#txtMobileNumber").keyup(function () {
GetCustomers();
});
});
function GetCustomers() {
var customerName = $.trim($("#txtMobileNumber").val());
$.ajax({
type: "POST",
url: "/Home/SearchCustomers",
data: "{customerName:'" customerName "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (customers) {
var table = $("#tblCustomers");
table.find("tr:not(:first)").remove();
$.each(customers, function (i, customer) {
var table = $("#tblCustomers");
var row = table[0].insertRow(-1);
$(row).append("<td />");
$(row).find("td").eq(0).html(customer.employee_name);
$(row).append("<td />");
$(row).find("td").eq(1).html(customer.mobile_number);
$(row).append("</a><td />");
$(row).find("td").eq(2).html(customer.service_plan);
$(row).append("<td />");
$(row).find("td").eq(3).html(customer.usuge_limit);
});
}
});
}
現在我想,如果我輸入一個手機號碼,手機號碼的列應該是一個超鏈接,以便用戶可以單擊它來查看他的資訊并進行編輯。
有點像使用 ActionResult 去 /Home/ViewPage/mobilenumberhere
這個可以在哪里添加?在 Js 代碼中高于還是低于?
uj5u.com熱心網友回復:
請在javascript中修改您的代碼
$('#tblCustomers tbody').html('');
$.each(customers, function (i, customer) {
$('#tblCustomers tbody').append(
'<tr>'
'<td >' customer.employee_name '</td> '
'<td style="text-align: left;font-size: x-large;" ><a target="_blank" href="/Home/ViewPage/' customer.mobile_number '">' customer.mobile_number ' </td> '
'<td >' customer.service_plan '</td> '
'<td >' customer.usuge_limit '</td> '
'</tr>'
);
//-------------- Second Option
$('#tblCustomers tbody').append(
'<tr>'
'<td >' customer.employee_name '</td> '
'<td style="text-align: left;font-size: x-large;" ><a onClick="fnLoadDetail(this)">' customer.mobile_number ' </td> '
'<td >' customer.service_plan '</td> '
'<td >' customer.usuge_limit '</td> '
'</tr>'
);
}
function fnLoadDetail(e) {
window.open('/Home/ViewPage/' e.text(),'_blank');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490417.html
標籤:javascript C# asp.net-mvc 模型视图控制器 控制器
上一篇:向控制器接收空值
