English 中文(简体)
MVC 3 网络网使整个网点可点击。
原标题:MVC 3 Webgrid make entire row clickable

I am using webgrid in my razor view in MVC 3. Below is how my webGrid looks, I want to make the entire row clickable and on click pass values to the javascript method also.

I am able to achieve calling my javascript method on text of all columns. I want the same to happen for click of anywhere on the entire row.

请就此向我提供指导。 成就

           @grid.GetHtml(

            columns: grid.Columns(

            grid.Column("CompanyName", format: @<text><a href="javascript:SubmitValues( @item.Col1 , @item.Col2 , @item.Col3 );">@item.CompanyName</a></text>, header: "ABC"),

            grid.Column("CompanyAddress", format: @<text><a href="javascript:SubmitValues( @item.Col1 , @item.Col2 , @item.Col3 );">@item.CompanyName</a></text>, header: "DEF"),

            ))      

         }
最佳回答

你们必须利用JQuery增加点击功能

Add htmlAttributes: new{id=“MainTable”} in You webgrid.

<script type="text/javascript">
   $(function () {
        var tr = $( #MainTable ).find( tr );
        tr.bind( click , function (event) {
            var values =   ;
            var tds = $(this).find( td );


            $.each(tds, function (index, item) {
                values = values +  td  + (index + 1) +  :  + item.innerHTML +  <br/> ;
            });
            alert(values);


        });
    }); 


</script>
问题回答

I have done this in my project with adding a class style: "click_able" on specific column like.

grid.Column("CompanyName", style: "click_able", format: @<text><a href="javascript:SubmitValues( @item.Col1 , @item.Col2 , @item.Col3 );">@item.CompanyName</a></text>, header: "ABC"),

然后添加点击功能。

<script type="text/javascript">
$(".click_able").click(function () {
    // Do something 
});

在我的案件中,它处以罚款。





相关问题
How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

ASP.NET MVC Razor view engine

After reading Scott Guthrie s blog entry about the new Razor view engine for ASP.NET MVC and reading this question comparing the available view engines. Razor seems to address most of the problems ...

Client Id for Property (ASP.Net MVC)

I m trying to do a label for a TextBox in my View and I d like to know, how can I take a Id that will be render in client to generate scripts... for example: <label for="<%=x.Name.ClientId%>"...

Get Current Area Name in View or Controller

How do you get the current area name in the view or controller? Is there anything like ViewContext.RouteData.Values["controller"] for areas?

MVC which submit button has been pressed

I have two buttons on my MVC form: <input name="submit" type="submit" id="submit" value="Save" /> <input name="process" type="submit" id="process" value="Process" /> From my Controller ...

热门标签