Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何在模式中编辑/删除数据库中的行_Asp.net Mvc_Asp.net Mvc 4_Twitter Bootstrap 3 - Fatal编程技术网

Asp.net mvc 如何在模式中编辑/删除数据库中的行

Asp.net mvc 如何在模式中编辑/删除数据库中的行,asp.net-mvc,asp.net-mvc-4,twitter-bootstrap-3,Asp.net Mvc,Asp.net Mvc 4,Twitter Bootstrap 3,我目前有一个html表,其中包含我存储在数据库中的许多客户端。我有它的设置,我可以创建一个客户端与模式在同一屏幕上。这很有效。我还在每行的末尾放了一支小铅笔和“x”图标。我希望能够在我点击铅笔时编辑行,在我点击X时删除行。我的工作原理是,当我点击图标时,会打开相应的模式,但我不知道如何跟踪需要编辑或删除的行。我希望在单击铅笔并打开模式时加载编辑模式中的表单信息。如果我没有使用模式,我知道我可以简单地使用@Html.ActionLink并传递行的ID,但我不知道如何从模式中获取该ID 我知道已经有

我目前有一个html表,其中包含我存储在数据库中的许多客户端。我有它的设置,我可以创建一个客户端与模式在同一屏幕上。这很有效。我还在每行的末尾放了一支小铅笔和“x”图标。我希望能够在我点击铅笔时编辑行,在我点击X时删除行。我的工作原理是,当我点击图标时,会打开相应的模式,但我不知道如何跟踪需要编辑或删除的行。我希望在单击铅笔并打开模式时加载编辑模式中的表单信息。如果我没有使用模式,我知道我可以简单地使用
@Html.ActionLink
并传递行的ID,但我不知道如何从模式中获取该ID

我知道已经有类似的问题了,其中很多我已经尝试过了,但都无济于事。以下是我认为相关的所有代码。我还使用了来自的Twiiter引导MVC助手方法


@使用(var table=Html.Bootstrap().Begin(新表().Striped()))
{            
@foreach(ViewBag.Fields中的SelectListItem字段)
{
@字段.文本
}
编辑
删除
foreach(ViewBag.Clients中的CPS.Models.Client客户端)
{
@client.firstName
@client.lastName
@client.mobileNumber
@客户机号码
@client.email
}
}
@*情态动词*@
@使用(var modal=Html.Bootstrap().Begin(new modal().Id(“CreateClientModal”).Closeable())
{
@modal.Header(“创建新客户机”)
使用(modal.BeginBody())
{
使用(var f=Html.Bootstrap().Begin(新表单().LabelWidthLg(3.LabelWidthSm(1)))
{
@Html.ValidationSummary()
@f、 FormGroup().TextBoxFor(m=>m.firstName)
@f、 FormGroup().TextBoxFor(m=>m.lastName)
@f、 FormGroup().TextBoxFor(m=>m.mobileNumber)
@f、 FormGroup().TextBoxFor(m=>m.homeNumber)
@f、 FormGroup().TextBoxFor(m=>m.email)
使用(modal.BeginFooter())
{
@f、 FormGroup().CustomControls(Html.Bootstrap().SubmitButton())
}
}
}
}
@使用(var modal=Html.Bootstrap().Begin(new modal().Id(“EditModal”).Closeable())
{
@modal.Header(“编辑客户端”)
使用(modal.BeginBody())
{
使用(var f=Html.Bootstrap().Begin(新表单().LabelWidthLg(3.LabelWidthSm(1)))
{
@Html.ValidationSummary()
@f、 FormGroup().TextBoxFor(m=>m.firstName)
@f、 FormGroup().TextBoxFor(m=>m.lastName)
@f、 FormGroup().TextBoxFor(m=>m.mobileNumber)
@f、 FormGroup().TextBoxFor(m=>m.homeNumber)
@f、 FormGroup().TextBoxFor(m=>m.email)
使用(modal.BeginFooter())
{
@f、 FormGroup().CustomControls(Html.Bootstrap().SubmitButton())
}
}
}
}
@使用(var modal=Html.Bootstrap().Begin(new modal().Id(“deletemodel”).Closeable())
{
@模态标题(“客户”)
使用(modal.BeginBody())
{
是否确实要删除选定的客户端

} 使用(modal.BeginFooter()) { @Html.Bootstrap().ActionLinkButton(“是”,“客户端”) } }

我真的很想得到一些帮助。

是否可以通过显示模式的路由传递ID?能否在每个表单中粘贴一个隐藏字段,并在显示模式之前用当前行的ID填充它?也许,我不知道,这就是我问的原因。我该怎么做?
<div class="row">
<div class="col-md-12">
    @using (var table=Html.Bootstrap().Begin(new Table().Striped()))
    {            
        <tr>
            @foreach (SelectListItem field in ViewBag.Fields)
            {
                <th>@field.Text</th>
            }
            <th>Edit</th>
            <th>Delete</th>
        </tr>
        foreach(CPS.Models.Client client in ViewBag.Clients)
        {
            <tr>
                <td>@client.firstName</td>
                <td>@client.lastName</td>
                <td>@client.mobileNumber</td>
                <td>@client.homeNumber</td>
                <td>@client.email</td>
                <td>
                    <a href="@Href("#EditModal")" role="button" data-toggle="modal" data-id="@client.id">
                        <img src="@Url.Content("~/Content/images/Edit.png")">
                    </a> 
                </td>
                <td>
                    <a href="@Href("#DeleteModal")" role="button" data-toggle="modal" data-id="@client.id" >
                        <img id="img_logo" alt="Logo" src="@Url.Content("~/Content/images/Delete.png")"/>
                    </a>                   
                </td>
            </tr>
        }
    }
</div>
</div>
@*Modals*@
@using (var modal = Html.Bootstrap().Begin(new         Modal().Id("CreateClientModal").Closeable()))
{
    @modal.Header("Create New Client")
    <div class="col-md-2"></div>
    using (modal.BeginBody())
    {
    using (var f = Html.Bootstrap().Begin(new Form().LabelWidthLg(3).LabelWidthSm(1)))
    {
        @Html.ValidationSummary()

        @f.FormGroup().TextBoxFor(m => m.firstName)
        @f.FormGroup().TextBoxFor(m => m.lastName)
        @f.FormGroup().TextBoxFor(m => m.mobileNumber)
        @f.FormGroup().TextBoxFor(m => m.homeNumber)
        @f.FormGroup().TextBoxFor(m => m.email)
        using (modal.BeginFooter())
        {
            @f.FormGroup().CustomControls(Html.Bootstrap().SubmitButton())
        }
    }
}

}

@using (var modal = Html.Bootstrap().Begin(new Modal().Id("EditModal").Closeable()))
{
    @modal.Header("Edit Client")
    using (modal.BeginBody())
    {
        using (var f = Html.Bootstrap().Begin(new Form().LabelWidthLg(3).LabelWidthSm(1)))
        {
        @Html.ValidationSummary()

        @f.FormGroup().TextBoxFor(m => m.firstName)
        @f.FormGroup().TextBoxFor(m => m.lastName)
        @f.FormGroup().TextBoxFor(m => m.mobileNumber)
        @f.FormGroup().TextBoxFor(m => m.homeNumber)
        @f.FormGroup().TextBoxFor(m => m.email)
        using (modal.BeginFooter())
        {
            @f.FormGroup().CustomControls(Html.Bootstrap().SubmitButton())
        }
    }
}
}

@using (var modal = Html.Bootstrap().Begin(new Modal().Id("DeleteModal").Closeable()))
{

    @modal.Header(" Client")
    using (modal.BeginBody())
    {
        <p>Are you sure you want to delete the selected client?</p>
    }
    using (modal.BeginFooter())
    {
        @Html.Bootstrap().ActionLinkButton("Yes","Clients")
    }
}