在网格中包含一个按钮

时间:2019-02-14 21:23:49

标签: javascript gridview asp.net-core-mvc syncfusion

我正在尝试添加按钮详细信息,以便允许转到页面详细信息

 $("#Grid").ejGrid({
                dataSource: ej.DataManager({
                 ...
columns: [
{ headerText: 'Detail', commands: ['type:"detail", buttonOptions:{text: "details", click:"OnClick"}} ],},
         ],

然后我定义了我的函数:

function OnClick(id){ var url = '@Url.Action("Detail","ServicesOrder", new {id="__id__"})'; window.location.href=url.replace('__id__',id); }

我的控制器ServicesOrder

 public IActionResult Detail(int id)
    {ServicesOrder ServicesOrder = _context.ServicesOrder.SingleOrDefault(x => x.ServicesOrderId.Equals(id));

        if (ServicesOrder == null)
        {
            return NotFound();
        }

        return View(ServicesOrder);
    }

我弄错了

找不到该站点页面:

https://本地主机:44337 / ServicesOrder / Detail / [object%20Object]

我已经把您的代码写到信上,但是没有用(参见图片)。 Error 2

谢谢

1 个答案:

答案 0 :(得分:0)

normally I would do this in a template with Syncfusion controls just works better and the tag-helpers just work.

//OPTION 1
//your original source
 $("#Grid").ejGrid({
                dataSource: ej.DataManager({
   columns: [
           { headerText: 'Detail' template: "<a href='/ServicesOrder/Details/{{:OrderId}}'>Finiched</a>"},
           { headerText: 'Order #', field: 'OrderId'}]
});

//OPTION 2
//your original source + tweak

 $("#Grid").ejGrid({
                dataSource: ej.DataManager({
   columns: [
           { headerText: 'Detail', template: true, templateId: "#detailsbutton"}]
});



<script type="text/x-jsrender" id="detailsbutton">
  <a class="btn btn-primary" href="@Url.Action("Details", "ServicesOrder", new {id = {{:OrderId}})>Details</a>
</script>

As long as the OrderId exists in the query for the grid it will find that in the template and populate accordingly. Keep in mind Syncfusion uses JSX extensively under the covers (at least this version which is EJs1, EJs2 is a complete rewrite using pure Javascript). I

I really have to emphasize that using just javascript with asp.net core mvc works but adding in clean tag-helpers like:

<ejs-grid id="OrderGrid" dataSource=@ViewBag.somedata >
    <e-datamanager></e-datamanager>
 <e-grid-columns>
    <e-grid-column field="Id" type="number"></e-grid-column>
 </e-grid-columns>
</ejs-grid>

So much easier to deal with!