ajax .beginform - OnFailure не возвращает частичное представление - PullRequest
1 голос
/ 10 января 2020

Здравствуйте

Я использую ajax .beginform, и я хочу вернуть частичное представление с ошибками внутри. Когда я изменяю код состояния на что-то плохое, чтобы запустить метод OnFailure, он не возвращает частичное представление. представление, которое называется:

<fieldset>
@using (Ajax.BeginForm("SaveSocioDetails", "Student", new AjaxOptions { HttpMethod = "POST", OnSuccess = "firstsuccess",OnFailure = "sociodetailsfail", UpdateTargetId="partialsocio" ,LoadingElementId = "div_loading" }, new { @enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
<div id="partialsocio">
    @Html.Action("PartialSocioDetails", "Student", new { SpId = ViewBag.SpId })
</div>
        <div id="div_loading" style="display:none;">
        <img src="@Url.Content("~/Content/Pic/Spinner.gif")" alt="" />
    </div>
    <button class="btn btn-primary" type="submit" value="Submit">שלח</button>
}
<input type="button" name="next" class="next action-button" value="Next" />

мой контроллер:

 [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult SaveSocioDetails(SpSocio socio) // ajax for 1 step in socio
        {
            socio.StudentId = sStudentId; // bind student id to socio model
            bool sociook = SocioDetValid(socio);
            // add validation
            if (ModelState.IsValid && sociook)
            {
                SaveSocioModel(socio);
                Response.StatusCode = 200;
            }
            else
               Response.StatusCode = 300; // return error to client the model is not valid
            return PartialView("~/Views/Student/Socio/SocioDetails.cshtml", socio); // return the partial view of the forn with validation messages
        }

js :

<script>
   $(document).ready(function ()
    {
    });

    function firstsuccess(data) {
        console.log(data);
        $('#partialsocio').html(data);
        console.log('this is ajaxSuccess');
    }

    function sociodetailsfail(bdata) {
         console.log('this is ajaxfail');
        console.log(data);
        $('#partialsocio').html(data);
    }
</script>

, пожалуйста, помогите мне с этим

1 Ответ

0 голосов
/ 10 января 2020

Если ваш запрос не удался, вы получите обратный вызов с сервера, включая определение проблемы внутри sociodetailsfail witin java -скрипта, где вы можете поместить logi c для отображения сообщений об ошибках, которые вы получаете с сервера bdata объект для пользователя

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...