我FormTemplate類在我的項目添加MVC中的jqGrid激活/關閉按鈕
public class FormTemplate : BaseEntity
{
public virtual string Name { get; set; }
public virtual DateTime? DateCreation { get; set; }
public virtual FormTemplateGroup Group { get; set; }
public virtual bool Active { get; set; }
public virtual FormTemplateStatus Status { get; set; }
public virtual IList<QuestionBlock> QuestionBlocks { get; set; }
public virtual bool IsFreeze { get; set; }
}
,我使用MVC的jqGrid http://mvcjqgrid.skaele.it/Home/Formatters
顯示頁面
@(Html.Grid("Grid")
.SetCaption("List")
.AddColumn(new Column("Name").SetLabel("Name"))
.AddColumn(new Column("GroupFor").SetLabel("Group"))
.AddColumn(new Column("DateCreation").SetLabel("Date"))
.AddColumn(new Column("Status").SetLabel("Status")).SetSortOnHeaderClick(false)
.AddColumn(new Column("Id").SetLabel(" ").SetCustomFormatter("buttonize").SetWidth(220).SetAlign(Align.Center))
.SetAutoWidth(false)
.SetRowNumbers(true)
.SetUrl(Url.Action("FormTemplateGridData"))
.SetAutoWidth(true)
.SetRowNum(10)
.SetRowList(new[] { 5, 10, 15, 20 })
.SetViewRecords(true)
.SetPager("Pager"))
我對FormTemplates名單在我的頁面上不顯示IsFreeze
屬性的值,但是如果IsFreeze == true
需要添加「激活」按鈕,並且對於每個FormTemplate都需要禁用按鈕。
我嘗試添加檢查功能buttonize
function buttonize(cellvalue, options, rowobject) {
var result = '<input type="button" value="Edit" onclick="editTemplate(' + options.rowId + ')">' + ' '
+ '<input type="button" value="Delete" onclick="deleteTemplate(' + options.rowId + ')">' + ' ';
if (isFreezeTemplate(rowobject[4])) {
result += '<input type="button" value="Activate" onclick="activateTemplate(' + options.rowId + ')">';
}
else {
result += '<input type="button" value="Deativate" onclick="deactivateTemplate(' + options.rowId + ')">';
}
return result;
}
添加功能
function isFreezeTemplate(id) {
var check = $.post('@Url.Action("IsFreezeFormTemplate")', { id: id });
return check;
}
,並在控制器
[HttpPost]
public bool IsFreezeFormTemplate(int id)
{
var formTemplate =
FormTemplateRepository.Query()
.Where(ft => ft.Id == id)
.SingleOrDefault();
if (formTemplate.IsFreeze == true) return true;
return false;
}
添加,但我只得到激活按鈕所有FormTemplates上我的頁面。
如何解決它?
您是否知道['$ .post'](http://api.jquery.com/jQuery.post/)是一個異步對象,它返回'jqXHR'對象,但不返回操作中返回的值?你應該有一個屬性,你發送到你的代碼,而不是... –
你能解釋我該怎麼辦? – Heidel