簡體   English   中英

MVC 3 \\表單提交按鈕不起作用

[英]MVC 3 \ form submit button not working

提交按鈕在FORM頁面中不起作用。 我已經閱讀了針對同一問題的許多解決方案,但無法解決該問題。 有人可以指出錯誤或建議更改...嗎?

abc.cshtml

     @using (Ajax.BeginForm("ABC", "Queries", null, new AjaxOptions { HttpMethod = "Post",  UpdateTargetId = "content", LoadingElementId = "mask" }, new { enctype = "multipart/form- data", id = "intake_form", **@class** = "inline-form clear_both" }))
    {


     <div class="form_row">
        <div class="form_col1">
            <label class="QueryPageHeadings">
                Title*</label>
        </div>
        <div class="form_col2" style="z-index: 24; position: relative;" id="queryTitle_div">
    @Html.TextBoxFor(m => m.ABC.QueryTitle, new { @class = "text QueryFormTextBox" })
            <br />
            <div style="float: left">
                @Html.ValidationMessageFor(m => m.ABC.QueryTitle)
            </div>
        </div>

    </div>
   <div class="form_row">
        <div class="form_col1">
            <label class="QueryPageHeadings">
                Specific Notes</label>
        </div>
        <div class="form_col2" style="z-index: 21; position: relative;" id="specific_note_div">
            @Html.TextAreaFor(m => m.ABC.SpecificNotes, new { @class = "text QueryFormTextBox", style = "resize:none;height:160px;" })
            <br />
            <div style="float: left">@Html.ValidationMessageFor(m => m.ABC.SpecificNotes)</div>

        </div>
    </div>
    <div class="form_row">
        <div class="form_col1">
            <label class="QueryPageHeadings">
                Supporting Document
            </label>
        </div>
        <div class="form_col2">
            <div style="width:100%;float:left;">
            @Html.TextBoxFor(m => m.ABC.SupportDocument, new { @Id = "lblFileName", @readonly = "readonly" })
            </div>
            <div style="width:100%;float:left;">
            <button id='btnUploadPopup' type="button" style="float:left;" onclick="javascript:OpenFileUpload();">
                Upload Files</button>
                </div>

        </div>

    </div>
    <div class="form_row form_footer">                          
        <p class="indent">
                <input class="secondary button float_right" value="Submit" type="submit" name="button" />                                 
        </p>
    </div>
     }

Controller.cs

    [HttpPost]
    public ActionResult ABC(ABCViewModel model, string button)
    {

            String errorMessage = "";
            if (String.IsNullOrEmpty(errorMessage))
            {
                errorMessage = errorMessage + " Fields can not be empty.";
            }
            if (!String.IsNullOrEmpty(errorMessage))
            {
                Session["errorMessage"] = errorMessage;
                IABC data = new ABCViewModel();

                data.ABC.QueryTitle = model.ABC.QueryTitle;
                data.ABC.SpecificNotes = model.ABC.SpecificNotes;
                data.ABC.SupportDocument = model.ABC.SupportDocument;

                TempData["isEdit"] = false;
                return View("ABC", data);
            }
            else
            {
                Session["errorMessage"] = "";
                Session.Remove("errorMessage");
            }


            Session["fileName"] = null;
            return View();

    }  

嘗試使用帶有httppost屬性的操作方法進行修飾

[HttpPost]
public ActionResult ABC(ABCViewModel model, string button)
{
   //your code
}

並將按鈕類型更改為“提交”

<button type="submit">....</button>

由於正在執行AJAX發布,因此您可能缺少必需的Java腳本。 在您的_Layout.chtml文件中添加以下內容。

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

另外,您還需要使用[HttpPost]屬性裝飾控制器方法。

PS:如果不需要異步擺姿勢,只需使用Html.BeginForm而不是Ajax.BeginForm

我已經復制粘貼了您的代碼“ AS-IS”,它對我有用。 差不多:)(由於編譯器錯誤,我已將' **@class** '更改為' @class ')。

嘗試在空項目上重復該操作。 也許您已經更改了某些內容?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM