代码之家  ›  专栏  ›  技术社区  ›  V Abdi

ajaxBeginForm on submit click not work and HTML。BeginForm将部分视图作为视图页返回

  •  0
  • V Abdi  · 技术社区  · 7 年前

    <section id="tabs-section">
    <ul id="myTab" class="my-nav nav nav-tabs  nav-justified responsive-tabs col-sm-12" style="padding:0;">
        <li class="active"><a href="#RegisterEditUsers" data-toggle="tab">A</a></li>
    </ul>
    
    <div class="tab-content col-sm-12" style="border:1px solid #000000;"@*margin-top:-20px;padding-top:20px;*@>
        <div class="tab-pane fade in active" id="RegisterEditUsers">@Html.Partial("RegisterEditUsers")</div>
            </div>
    

    当我点击 此视图中的局部视图显示在“链接”下。局部视图如下:

    <div class="panel" style="border:1px solid #ff6a00;margin:10px 10px 0 
    10px;padding:10px;">
    <div class="row ">
            <div id="register" class="col-sm-6 col-sm-offset-0 col-sm-pull-0 
    col-sm-push-6 col-xs-offset-3 col-xs-pull-1 btn btn-circle ">
                @Ajax.ActionLink("AA", "Register", "Account", new AjaxOptions { 
    HttpMethod = "Get", UpdateTargetId = "Result", InsertionMode = 
    InsertionMode.Replace, OnComplete = "regClick" })
            </div>
    
            <div id="edit" class="col-sm-6 col-sm-offset-3 col-xs-offset-0 btn 
    btn-circle">
                @Ajax.ActionLink("BB", "GetUsers", "UsersAdmin", new AjaxOptions 
    { HttpMethod = "Get", UpdateTargetId = "Result", InsertionMode = 
    InsertionMode.Replace, OnComplete = "edClick" })
            </div>
        </div>
    </div>
    <div class="panel" style="border:1px solid #ff6a00;margin:0px 10px 10px 
    10px;">
    <div id="Result" dir="rtl"></div>
    </div>
    

    最后当我选择

        @using (Ajax.BeginForm(
        "Register", 
        "Account", 
        null, 
        new AjaxOptions
    {
        HttpMethod = "Post",
        UpdateTargetId = "IdentifyPerson",
        InsertionMode = InsertionMode.Replace
      }))
      {
        @Html.AntiForgeryToken();
        @Html.ValidationSummary(true, "", new { @class = "text-danger" });
    
        <div id="IdentifyPerson" style="padding:10px">
            <div class="panel" style="padding:10px; direction:rtl">
    
                <div class="row">
                    <div class="form-group col-md-2">
                        <label class="sr-only" for="LastName">:</label>
                        @*<input type="text" class="form-control" id="LastName" 
    placeholder="" name="LastName">*@
                        @Html.TextBoxFor(c => c.LastName, new { @class = "form-
    control", placeholder = "" })
                        @Html.ValidationMessageFor(model => model.LastName, "", 
    new { @class = "text-danger" })
                    </div>
                </div>
                <div class="row">
                    <div class="pull-left">
                        <button type="submit" id="RegisterBtn" 
    name="RegisterBtn" class="btn btn-info" style="padding:10px">AAA</button>
                    </div>
                </div>
            </div>
        </div>
     }
    

    一切都很顺利,直到我点击提交按钮( AAA级 ),什么都没有发生。我在页面中也使用这一行:

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

    如果我使用 ajaxBeginForm公司 提交按钮工作正常,但在返回部分,当我想加载第二个部分视图时,它被加载为一个视图!! 我想要的是:当我点击提交按钮Ajax时。BeginForm或HTML。beginForm工作,返回的页面显示为部分视图而不是视图。 有人能帮我吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   V Abdi    7 年前

    多亏了Stephen Muecke,bundle似乎无法正常工作。我真的不知道为什么,我只是直接在局部视图中添加了这四行,效果很好:)

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