网格按钮后 [英] Post Button in Grid

查看:154
本文介绍了网格按钮后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格许多产品(表)。

每一行都有一个自己的按钮,删除和编辑产品。

现在我的问题是:如何才能选中了哪个表行后消息后,确定

此致

 <表ID =tbltraining级=tblStyle>
&所述; TR类=tblHearerRow>
    百分位类=tblHearerCell的风格=宽度:50像素;>    < /第i
    百分位类=tblHearerCell的风格=宽度:50像素;>    < /第i
    百分位类=tblHearerCell的风格=宽度:200像素;>
        名称
    < /第i
    百分位类=tblHearerCell的风格=宽度:100像素;>
        价钱
    < /第i
    百分位类=tblHearerCell>
        操作
    < /第i
< / TR>
@foreach(在Model.Products VAR项)
{
    < TR类=tblRow的风格=背景色:#c4cbf8>
        < TD ID =的itemId级=itemIdClass tblColumn>
            @ Html.DisplayFor(modelItem => item.Id)
        < / TD>
        < TD类=tblColumn的风格=字体重量:大胆;>
            @ Html.DisplayFor(modelItem => item.Name)
        < / TD>
        < TD类=tblColumn>
            @ Html.DisplayFor(modelItem => item.Price)
        < / TD>
        < TD类=tblColumn>
            <输入类型=按钮值=编辑
                   类=buttonEdit btnStyleOne/>
            <输入类型=按钮值=删除
                   类=buttonDelete btnStyleOne/>
            <输入类型=按钮值=添加类别
                   类=buttonDelete btnStyleOne/>
        &所述; TD>
    < / TR>


解决方案

您最好的和最简单的办法就是使用表单标签。有没有限制多少可以形成有一个页面上。

 <形式的行动=@ Url.Action(删除,产品,新{ID = item.ID})方法=POST>
     <按钮式=提交>删除< /按钮>
< /表及GT;

您可以得到真正看中,并创建一个helper方法,或者局部视图,但基本上是你所需要的。

使用HttpVerb 加分删除

I have many products in grid (table).

Every row has an own button to delete and edit the product.

Now my question is: How can I identify after post message which table row was selected?

Best Regards

<table id="tbltraining" class="tblStyle">
<tr class="tblHearerRow">
    <th class="tblHearerCell" style="width:50px;">

    </th>
    <th class="tblHearerCell" style="width:50px;">

    </th>
    <th class="tblHearerCell" style="width:200px;">
        Name
    </th>
    <th class="tblHearerCell" style="width:100px;">
        Price
    </th>
    <th class="tblHearerCell">
        Actions
    </th>
</tr>
@foreach (var item in Model.Products)
{
    <tr class="tblRow" style="background-color:#c4cbf8">
        <td id="itemId" class="itemIdClass tblColumn">
            @Html.DisplayFor(modelItem => item.Id)
        </td>
        <td class="tblColumn" style="font-weight:bold;">
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td class="tblColumn">
            @Html.DisplayFor(modelItem => item.Price)
        </td>
        <td class="tblColumn">
            <input type="button" value="Edit"
                   class="buttonEdit btnStyleOne" />
            <input type="button" value="Delete"
                   class="buttonDelete btnStyleOne" />
            <input type="button" value="Add Category"
                   class="buttonDelete btnStyleOne" />
        <td>
    </tr>

解决方案

Your best and most simple option is just to use the form tag. There is no restriction to how many forms you can have on a page.

<form action="@Url.Action("delete","products", new { id = item.ID })" method="POST">
     <button type="submit">Delete</button>
</form>

You can get really fancy and create a helper method or partial view, but that is basically all you need.

Extra points for using the HttpVerb DELETE.

这篇关于网格按钮后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆