将html.beginform放入bootstrap模式中

时间:2015-05-03 01:22:30

标签: jquery html asp.net-mvc twitter-bootstrap

我想将一个html.beginform 放在一个bootstrap模式中,该模式会发布到控制器操作方法。

引导模式出现正常,但是当我点击“保存”按钮时,它不会发布到我的方法。

注意我的控制器Edit方法上有正确的ViewModel名称和HttpPost方法。

请注意下面的图像显示左下方的链接似乎是“GET”(请参阅​​链接末尾的“2”): enter image description here

提交“保存”按钮后,我从Fiddler那里得到了以下信息。

GET http://localhost:7683/__browserLink/requestData/c7214b476210499781860a178a6b7607?version=2 HTTP/1.1
X-Requested-With: XMLHttpRequest
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:7683/Projects/Project/Edit/2?Name=A%26C+CaseTracker&Description=Keeps+track+of+all+dental+cases.&CustomerID=2&CategoryID=10&PriorityID=1&StatusID=4&Quote=509.00&Notes=Plus+maintenance+costs.
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:7683
DNT: 1
Connection: Keep-Alive

在我的“HTTPGET”方法上放置一个断点之后,即使在我告诉它进行POST的表单中,它也会点击

@using (Html.BeginForm("Edit", "Project", FormMethod.Post))

有人可以告诉我我做错了吗?

这是我的html:

@model YeagerTechDB.Models.Project

@{
    ViewBag.Title = "Edit Project";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit Project</h2>

<div class="modal" id="projectEditModal" tabindex="-1" role="dialog" aria-labelledby="projectModal-label" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="projectModal-label">Edit Project: Project: @Model.ProjectID</h4>
            </div>
            <div class="modal-body">
                @using (Html.BeginForm("Edit", "Project", FormMethod.Post))
                {
                   <div class="form-group">
                        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                        <div class="form-group">
                            @Html.LabelFor(model => model.Name, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control", @placeholder = "ProjectName" } })
                                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Description, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                                @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control", @placeholder = "Description" } })
                                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Customer.Email, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
                                @Html.DropDownListFor(model => model.CustomerID, new SelectList(ViewBag.Customers, "CustomerID", "Email", Model.CustomerID), "-- Select Customer --", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.CustomerID, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Category.CategoryDescription, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                                @Html.DropDownListFor(model => model.CategoryID, new SelectList(ViewBag.Categories, "CategoryID", "CategoryDescription", Model.CategoryID), "-- Select Category --", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.CategoryID, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Priority.PriorityDescription, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                                @Html.DropDownListFor(model => model.PriorityID, new SelectList(ViewBag.Priorities, "PriorityID", "PriorityDescription", Model.PriorityID), "-- Select Priority --", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.PriorityID, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Status.StatusDescription, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                                @Html.DropDownListFor(model => model.StatusID, new SelectList(ViewBag.Statuses, "StatusID", "StatusDescription", Model.StatusID), "-- Select Status --", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.StatusID, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        @Html.LabelFor(model => model.Quote, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                        <div class="form-group">
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
                                @Html.EditorFor(model => model.Quote, new { htmlAttributes = new { @class = "form-control", @placeholder = "Quote" } })
                                @Html.ValidationMessageFor(model => model.Quote, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        @Html.LabelFor(model => model.Quote, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                        <div class="form-group">
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
                                @Html.EditorFor(model => model.Notes, new { htmlAttributes = new { @class = "form-control", @placeholder = "Notes" } })
                                @Html.ValidationMessageFor(model => model.Notes, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.CreatedDate, new { @class = "control-label col-offset-1 col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                                @Html.EditorFor(model => model.CreatedDate, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
                            </div>
                            @Html.LabelFor(model => model.UpdatedDate, new { @class = "control-label col-lg-2 col-md-2 col-sm-2 col-xs-2" })
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
                                @Html.DisplayFor(model => model.UpdatedDate, new { htmlAttributes = new { @class = "form-control" } })
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <a href="#" class="btn" data-dismiss="modal">Close</a>
                        <button type="submit" class="btn btn-success" id="btnSaveProject">Save</button>
                    </div>
                }
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        $(document).ready(function ()
        {
            $('#projectEditModal').modal('show');
        });
    </script>
}

这是我的编辑帖子方法:

 [HttpPost]
               public async Task<ActionResult> Edit(Project project)
        {
            if (ModelState.IsValid)
            {
                //await db.EditProjectAsync(project);
            }

            List<CustomerDDL> customerList = await db.GetCustomerDDLAsync();
            ViewBag.Customers = customerList;

            List<Category> categoryList = await db.GetCategoriesAsync();
            ViewBag.Categories = categoryList;

            List<Priority> priorityList = await db.GetPrioritiesAsync();
            ViewBag.Priorities = priorityList;

            List<Status> statusList = await db.GetStatusesAsync();
            ViewBag.Statuses = statusList;

            return View(project);
        }

2 个答案:

答案 0 :(得分:1)

您需要从data-dismiss="modal"中取出div class="modal-footer"。我有同样的问题,这对我有用。希望它也适合你。

答案 1 :(得分:0)

试试这个

JCL:
//OMEGAPL  EXEC  PGM=IKJEFT01                                                 
//STEPLIB  DD    DISP=SHR,DSN=SYS1.DB2DR.DSNLOAD                                
//SYSTSPRT DD SYSOUT=*                                                       
//SYSPRINT DD SYSOUT=*                                                       
//SYSTSIN  DD *                                                              
  DSN SYSTEM(DBS1)                                                           
  BIND PLAN     (KO2PLAN)        +                                           
       PKLIST   (KO2OM520.*)     +                                           
       OWNER    (SOFDB2)         +                                           
       ACTION   (REPLACE)        +                                           
       EXPLAIN  (NO)             +                                           
       RETAIN                    +                                           
       VALIDATE (BIND)           +                                           
       ENCODING (EBCDIC)         +                                           
       ISOLATION(UR)                                                         
  END                                                                        
/*                                                                           

SYSOUT:
DSNT500I  -DRS1 DSNTBCM1 RESOURCE      UNAVAILABLE                                    
       REASON 00E30083                                                       
       TYPE 00000800                                                         
       NAME KO2PLAN                                                          
DSNT201I  -DRS1  BIND FOR PLAN KO2PLAN  NOT SUCCESSFUL