current position:Home>New Ajax options {onsuccess} migration core in MVC

New Ajax options {onsuccess} migration core in MVC

2022-02-02 20:25:20 CSDN Q & A

MVC If the form is submitted successfully, the front end will be executed js Of OnSuccess = "doResult"

@using (Ajax.BeginForm("ModifyPhoneOverseas", "ResumeUpdate", FormMethod.Post, new AjaxOptions { OnSuccess = "doResult" }))    {    }

stay NET CORE Inside new AjaxOptions { OnSuccess = "doResult" }) How to write it ?




Refer to the answer 1:

stay ASP.NET Core No longer used in Ajax.BeginForm, But use Html.AjaxBeginForm.
Complete process :

  1. Install the package with the following command :
PM> Install-Package AspNetCore.Unobtrusive.Ajax

2. Register this package with Startup.cs:

public void ConfigureServices(IServiceCollection services){    //...    services.AddUnobtrusiveAjax();     //services.AddUnobtrusiveAjax(useCdn: true, injectScriptIfNeeded: false);    //...}public void Configure(IApplicationBuilder app){    //...    app.UseStaticFiles();    //It is required for serving 'jquery-unobtrusive-ajax.min.js' embedded script file.    app.UseUnobtrusiveAjax(); //It is suggested to place it after UseStaticFiles()    //...}

3. hold js File added to _Layout.cshtml Inside :

<!--Place it at the end of body and after jquery-->    @Html.RenderUnobtrusiveAjaxScript()    <!-- Or you can reference your local script file -->    @RenderSection("Scripts", required: false)</body></html>

4. As for what you said, I want to know how to achieve new AjaxOptions { OnSuccess = "doResult" }), This method is used to do some operations when ajax success postback. stay ASP.NET Core Set in :

@{    AjaxOptions ajaxOptions = new AjaxOptions    {        HttpMethod = "POST",        OnSuccess="doResult"        //other options....    };}@using (Html.AjaxBeginForm("ActionName", "ControllerName", ajaxOptions)){    //other elements...    <input type="submit"  value="Submit Details" />}//....



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022025180576.html

Random recommended