话不多说,上代码吧。
创建一个Controller
public class TNewsController : Controller
{
public ActionResult Index()
{
return View();
}
}
对应的View片段,
<pre name="code" class="html"><div id="content">
<div id="toolbarTNews">
<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" οnclick="newobj('新闻', 'TNews')">增加新闻</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" οnclick="editobj('TNews', '新闻', 'NewsId')">修改新闻</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" οnclick="destroyobj('TNews', '新闻', 'NewsId')">删除新闻</a>
<input class="easyui-searchbox" data-options="prompt:'输入新闻标题进行搜索',searcher:doSearch" style="width: 300px" />
<script>
function doSearch(value) {
$('#dgTNews').datagrid('reload', { query: value }); //查询条件,自己控制啦,在负责API对应Controller的Aciton里自己加就行了
}
</script>
</div>
<table id="dgTNews" class="easyui-datagrid" data-options="url:'../../../Api/TNews/Index',resizable:true,modal:true,singleSelect:true" rownumbers="true"
pagination="true" toolbar="#toolbarTNews">
<thead>
<tr>
<th data-options="field:'NewsId',hidden:true,width:80">新闻Id</th>
<th data-options="field:'NewsTitle',width:280">新闻名称</th><th data-options="field:'NewsDateTime',width:80,<span style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px; line-height: 23.1px;">sortable='true'</span>">新闻时间</th>
<th data-options="field:'NewsStatus',width:80,align:'left'" formatter="formatterstatus">新闻状态</th>
</tr>
</thead>
</table>
</div>
负责给data-options 的url提供API的Controller以及Action,不要用APIController,因为你不能随心所欲的返回动态对象了,返回个dynamic又太别扭,维护Model也是相当大的工作量啊(问题在这,哈哈,人懒)。
public class TNewsController : Controller
{
/// <summary>
///
/// &l