Posts

Showing posts with the label jQuery Ajax

Pass the Selected Values ​​of the ListBox from View to Controller in ASP.NET Core Using jQuery Ajax

Image
This article describes how to pass/send the selected ListBox value to the controller using jQuery Ajax. Let's see it through 4 steps. Step 1: Controller The following is a controller code. Microsoft.AspNetCore.Mvc.Rendering is included to use the SelectListItem class. The controller has two action methods, Index() and SampleViewModel() . In the code, a list of movie names is sent to the viewer to bind to the list box. The SampleViewModel() method retrieves the selected movie ID and text and sends it to the results view. HomeController.cs using Microsoft.AspNetCore.Mvc.Rendering; public class HomeController : Controller {    public IActionResult Index()     {         List<SelectListItem> MoviesList = new List<SelectListItem>         {             new SelectListItem { Value = "1", Text = "Zootopia" },             new SelectListItem { Value =...

Upload file in ASP.NET Core MVC using jQuery Ajax

Image
This article is going to explain how to upload a file in ASP.NET Core MVC using jQuery Ajax. The following is a controller code. Here IWebHostEnvironment is injected via the HomeController constructor to get the root path. In the FileUpload action method the parameter IFormFile has been passed to upload the files. Note: To save the uploaded file, create a folder name Upload in wwwroot.   using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using System.IO; public class HomeController : Controller {     private readonly IWebHostEnvironment _env;     public HomeController(IWebHostEnvironment hostingEnv)     {         _env = hostingEnv;     }     public IActionResult Index()     {         return View();     }     public async Task<IActionResult...

Pass HTML Content from View to Controller using jQuery Ajax

Image
This blog is going to explain how to send a large amount of text content or HTML content from the view to the controller using jQuery Ajax. Ajax means Asynchronous JavaScript and XML. It helps you to load the server data without refreshing the browser. So you can refresh part of the web page without loading the entire page. jQuery Ajax performs asynchronous Ajax requests. The following is a view code. Here I have included the Google jQuery CDN (If you want you can download the jQuery library and include the link). Also, I have added some text boxes and textarea to collect the input values. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <table class="width-hundred-percent">     <tr>         <td> ID: </td>         <td> <input id="idTextBox" type="text" style="width:100%" /> </td>     </tr>     <tr> ...