Posts

Showing posts from May, 2017

ASP.Net MVC Core: Javascript files in Areas along with Views (.cschtml)

Areas in MVC allow you to separate your web application into segments, each with their own set of Controllers and Views, for better organization and intuitive access via routing.   Here I want to manage my static java script files particular objects in areas i.e. I want to place my CountryDetail.js and CountryGrid.js files in Areas/Setup/Country Folder along with CountryDetail.cshtml and CountryGrid.cshtml. As you know, in .Net Core, as part of the OWIN pipeline , no static files are rendered by default including those in the "wwwroot" folder. Where things used to be handled in web.config, now everything goes through the OWIN pipeline. You have to add the StaticFile Middleware which will allow those to be rendered. The default implementation allows all files under "wwwroot" to be rendered. public void Configure ( IApplicationBuilder app) {     app. UseStaticFiles (); } Here is the official Microsoft documentation:  Working with StaticFiles in

ASP.Net Core: Post JSON data to Api Controller

To post JSON data to web api controller in MVC Core is little bit change. public class StudentController : Controller { [ HttpPost ] public IActionResult AddStudent ( Student student ) { return Ok() ; } } public class Student { public string FirstName { get ; set ; } public string LastName { get ; set ; } public int Age { get ; set ; } } Here we have a model student and a Post Method in StudentController i.e. AddStudent.  So where does the  Student   parameter come from? Model binding to the rescue! There are a number of different places the model binders can look for data in order to hydrate the person object. The model binders are highly extensible, and allow custom implementations, but common bindings include: Route values - navigating to a route such as  {controller}/{action}/{id}  will allow binding to an  id parameter Querystrings - If you have passed variables as querystring parameters such as