0
這是我在剃刀代碼視圖,基本上從數據庫中提取信息顯示錶 -如何更新模型值,並重新加載在Razor視圖一個div在MVC
@model List<EmpoyeeInfo.Models.FFX_HR_Employees>
@using System.Reflection;
@{
ViewBag.Title = "Employee Information";
var Properties = Model[0].GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList();
string[] head = new string[Properties.Count()];
}
<div id="web-top">
<div id="horizontal-line"></div>
<input class="search-box-text" type="text" spellcheck="false" placeholder="Search Individual Record..." title="Search Individual Record" id="searchbox" name="searchbox" />
</div>
<div id="web-main">
<table class="employee-info">
<tr>
@foreach (var Property in Properties)
{
if (Property.Name.Equals("AnnualHolidayEntitlement"))
{
<th colspan="2">@Property.Name</th>
}
else
{
<th>@Property.Name</th>
}
}
</tr>
@foreach(var Row in Model)
{
<tr>
@{
Type type = Row.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(type.GetProperties());
}
@foreach (PropertyInfo prop in props)
{
if (prop.Name.Equals("AnnualHolidayEntitlement"))
{
<td contenteditable="true">@prop.GetValue(Row, null)</td>
}
else
{
<td>@prop.GetValue(Row, null)</td>
}
}
<td class="saveToDB">SAVE</td>
</tr>
}
</table>
</div>
但正如我在鍵入搜索箱文本,Ajax調用是由 -
$(document).ready(function() {
$('.search-box-text').keypress(function() {
getReport($(this).html());
});
})
function getReport(Name) {
$.ajax({
url: '@Url.Action("Index", "Home")',
type: 'POST',
data: { Name: Name },
dataType: "json",
cache: false,
success: function (result) {
//do stuff;
},
error: function() {
console.log("no display");
}
});
}
現在我該怎樣重新加載DIV - 「網絡主」和更新模型值,使得作爲一個名稱的用戶搜索,該表也需要更新。
有沒有辦法改變模型的值? 類似於 - @Model = data(在腳本部分) –
您應該在Index操作中操縱HomeController中的數據。從索引操作返回值後,可以將html附加到div – Yasirmx