BeginForm设置错误的

BeginForm设置错误的

如下代码:

@using res = Resouces;
@model Model
@using (Ajax.BeginForm("Excuse", "Profile", new AjaxOptions() {
    HttpMethod = "POST",
    OnSuccess = "$('#excuse').modal('hide')"
}, new { @class = "form-horizontal" })) {
    <div class="modal fade" id="excuse" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-fullscreen form-horizontal">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3 class="modal-title">@res.Profile.Excuse</h3>
                </div>
                <div class="modal-body">
                    @Html.HiddenFor(id => id.UserId)
                    <div class="form-group">
                        @Html.LabelFor(grp => grp.Reason, new { @class = "col-lg-1 control-label" })
                        <div class="col-lg-11">
                            @Html.TextAreaFor(grp => grp.Reason, new { @class = "form-control", style = "height: 400px;", rows = "10", placeholder = Html.DisplayNameFor(grp => grp.Reason) })
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal" type="button">@res.Resources.Cancel</button>
                    <button class="btn btn-primary" type="submit">@res.Profile.Excuse</button>
                </div>
            </div>
        </div>
    </div>
}


这是我得到的输出:

<form class="form-horizontal" id="form0" action="/gekkota/Presence/Excuse?Length=7" method="post" novalidate="novalidate" data-ajax-method="POST" data-ajax="true" data-ajax-success="$('#excuse').modal('hide')" data-ajax-url="/Profile/Excuse">    <div tabindex="-1" class="modal fade in" id="excuse" role="dialog" aria-hidden="false" style="display: block;">
        <div class="modal-dialog modal-fullscreen form-horizontal">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" aria-hidden="true" type="button" data-dismiss="modal">×</button>
                    <h3 class="modal-title">Entschuldigen</h3>
                </div>
                <div class="modal-body">
                    <input name="UserId" id="UserId" type="hidden" value="1" data-val-required='Das Feld "UserId" ist erforderlich.' data-val="true" data-val-number='Das Feld "UserId" muss eine Zahl sein.'>
                    <div class="form-group">
                        <label class="col-lg-1 control-label" for="Reason">Begründung</label>
                        <div class="col-lg-11">
                            <textarea name="Reason" class="form-control" id="Reason" style="height: 400px;" placeholder="Begr&amp;#252;ndung" rows="10" cols="20">Begr&amp;#252;ndung</textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" type="button" data-dismiss="modal">Abbrechen</button>
                    <button class="btn btn-primary" type="submit">Entschuldigen</button>
                </div>
            </div>
        </div>
    </div>
</form>


这是我期望的输出:

<form class="form-horizontal" id="form0" action="/gekkota/Profile/Excuse?Length=7" method="post" novalidate="novalidate" data-ajax-method="POST" data-ajax="true" data-ajax-success="$('#excuse').modal('hide')" data-ajax-url="/Profile/Excuse">    <div tabindex="-1" class="modal fade in" id="excuse" role="dialog" aria-hidden="false" style="display: block;">
        <div class="modal-dialog modal-fullscreen form-horizontal">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" aria-hidden="true" type="button" data-dismiss="modal">×</button>
                    <h3 class="modal-title">Entschuldigen</h3>
                </div>
                <div class="modal-body">
                    <input name="UserId" id="UserId" type="hidden" value="1" data-val-required='Das Feld "UserId" ist erforderlich.' data-val="true" data-val-number='Das Feld "UserId" muss eine Zahl sein.'>
                    <div class="form-group">
                        <label class="col-lg-1 control-label" for="Reason">Begründung</label>
                        <div class="col-lg-11">
                            <textarea name="Reason" class="form-control" id="Reason" style="height: 400px;" placeholder="Begr&amp;#252;ndung" rows="10" cols="20">Begr&amp;#252;ndung</textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" type="button" data-dismiss="modal">Abbrechen</button>
                    <button class="btn btn-primary" type="submit">Entschuldigen</button>
                </div>
            </div>
        </div>
    </div>
</form>


如何获得我期望的代码?

最佳答案

因为您没有调用正确的重载方法。尝试用5个参数调用一个。例:

@using (Ajax.BeginForm("Excuse", "Profile",null, new AjaxOptions() {...}, new { @class = "form-horizontal" }))

关于asp.net-mvc - Ajax.BeginForm设置错误的 Action ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21534752/

10-10 12:26