MVC 3 \表单提交按钮不起作用

时间:2022-11-23 16:45:58

Submit Button is not working in FORM page. I have read many solutions for the same question, but not able to rectify the problem. Can somebody please point out the error or suggest change...??

提交按钮无法在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();

    }  

3 个解决方案

#1


0  

try to decorate with action method with the httppost attribute

尝试使用httppost属性的action方法进行装饰

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

and change the button type to 'submit'

并将按钮类型更改为“提交”

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

#2


0  

You might be missing the required java scripts since you are doing an AJAX post. Add the following in your _Layout.chtml file.

由于您正在执行AJAX帖子,因此可能缺少必需的Java脚本。在_Layout.chtml文件中添加以下内容。

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

Also you need to decorate your controller method with [HttpPost] attribute.

您还需要使用[HttpPost]属性修饰控制器方法。

PS: If you do not need asynchronous posing, just use Html.BeginForm instead of Ajax.BeginForm.

PS:如果你不需要异步冒充,只需使用Html.BeginForm而不是Ajax.BeginForm。

#3


0  

I've copy-pasted your code "AS-IS" and it works for me. Almost :) (I've changed '**@class**' to '@class' because of compiler error).

我已经“按原样”复制了你的代码,它对我有用。几乎:)(由于编译器错误,我已将'** @ class **'更改为'@class')。

Try to repeat it on the empty project. Maybe you have changed something?

尝试在空项目上重复它。也许你改变了什么?

#1


0  

try to decorate with action method with the httppost attribute

尝试使用httppost属性的action方法进行装饰

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

and change the button type to 'submit'

并将按钮类型更改为“提交”

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

#2


0  

You might be missing the required java scripts since you are doing an AJAX post. Add the following in your _Layout.chtml file.

由于您正在执行AJAX帖子,因此可能缺少必需的Java脚本。在_Layout.chtml文件中添加以下内容。

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

Also you need to decorate your controller method with [HttpPost] attribute.

您还需要使用[HttpPost]属性修饰控制器方法。

PS: If you do not need asynchronous posing, just use Html.BeginForm instead of Ajax.BeginForm.

PS:如果你不需要异步冒充,只需使用Html.BeginForm而不是Ajax.BeginForm。

#3


0  

I've copy-pasted your code "AS-IS" and it works for me. Almost :) (I've changed '**@class**' to '@class' because of compiler error).

我已经“按原样”复制了你的代码,它对我有用。几乎:)(由于编译器错误,我已将'** @ class **'更改为'@class')。

Try to repeat it on the empty project. Maybe you have changed something?

尝试在空项目上重复它。也许你改变了什么?