0

我终于得到了我的 asp.net 网格来显示数据......但是我需要它在单击其中一行时链接到一个动作......或者如果需要,单列我怎样才能获得进入其中之一的路由我在 MVC3 中的列或行?

我正在使用 jqGrid 顺便说一句...

这是我设置网格的方式

$("#list").jqGrid({
                        shrinkToFit: false,
                        autowidth: true,
                        datatype: 'jsonstring',
                        mtype: 'POST',
                        colNames: [
                                   'MRN',
                                   'Hospital Fin',
                                   'First Name',
                                   'Last Name',
                                   'Date of birth',
                                   'Completed Pathway',
                                   'Completed Pathway Reason',
                                   'PCP Appointment',
                                   'Specialist Appointment',
                                   'Admit Date'
                                   ],
                        colModel: [
                                   { name: 'MRN', width: 125, align: 'left' },
                                   { name: 'Hospital_Fin', width: 145, align: 'left' },
                                   { name: 'First_Name', width: 115, align: 'left' },
                                   { name: 'Last_Name', width: 115, align: 'left' },
                                   { name: 'Date_of_birth', width: 145, align: 'left' },
                                   { name: 'Completed_Pathway', width: 125, align: 'left' },
                                   { name: 'Completed_Pathway_Reason', width: 165, align: 'left' },
                                   { name: 'PCP_Appointment', width: 115, align: 'left' },
                                   { name: 'Specialist_Appointment', width: 125, align: 'left' },
                                   { name: 'Admit_Date', width: 185, align: 'left' }],
                        rowNum: 10,
                        rowList: [5, 10, 20, 50],
                        sortname: 'Id',
                        sortorder: "desc",
                        viewrecords: true,
                        imgpath: '/Content/themes/UPMC-theme/images',
                        caption: 'My first grid'
    });

有什么方法可以使整行可点击到操作方法?要打开我的视图,我需要调用一个控制器和一个动作......

EditEncoutner 是控制器,EditEncounter 是 Action...

public ActionResult EditEncounter(int encounterId, int popId)
        {
            string UID = HttpContext.User.Identity.Name;
            DataRepository dr = new DataRepository();
            PatientACOModel patMod = dr.Get(encounterId, UID);
            TempData["POPULATIONID"] = popId;
            return View(patMod);
        }

现在我自己编写 JSON 字符串......我想<a />在相关列中放置一个标签。但这意味着我不会让整行都可点击,然后我必须选择放置链接的列......我可以制作一个编辑列,如果其他所有方法都失败了,我会这样做,我是然而,有点希望有一个更优雅的解决方案。

4

1 回答 1

1

假设您的 View 绑定到一个ListProducts对象

@model IEnumerable<Product>
<table>
@foreach(var product in Model)
{
 <tr class="trClickable" data-viewurl="@Url.Action("View","Product",new {@id=product.ID})">
   <td>
     @product.Name
   </td>
   <td>
     @product.Price
   </td>
 </tr>
}
</table>

我们将添加一些 javascript 来click捕获row.

<script type="text/javascript">
 $(function () {
     $(".trClickable").click(function () {
         var item = $(this);
         window.location.href = item.data("viewurl");
     });
 });

View假设您在内部调用了一个操作方法ProductController,该方法接受一个调用的参数id并在其视图中显示一些数据

于 2012-07-12T21:31:02.107 回答