JSON Parameter in ASP.NET MVC using [FromBody]

To force Web API to read a simple type from the request body, add the [FromBody] attribute to the parameter:

public class Person
    public string FirstName { get; set; }
    public string LastName { get; set; }
[Route("hello2"), HttpPost]
public JsonResult Hello2([FromBody] Person person)
    string output = $@"Hello {person.FirstName} {person.LastName}";
    return Json(output);

When a parameter has [FromBody], Web API uses the Content-Type header to select a formatter. In this example, the content type is “application/json” and the request body is a raw JSON string (not a JSON object).


Return JSON Data from ASP.NET MVC Controllers

Send JSON Content welcome note based on user type

using System;  
using System.Collections.Generic;  
using System.Text;  
using System.Web.Mvc;  
using System.Web.Script.Serialization;  
using JsonResultDemo.Models;  
namespace JsonResultDemo.Controllers  
    public class JsonDemoController : Controller  
        #region ActionControllers  
        /// <summary>  
        /// Welcome Note Message  
        /// </summary>  
        /// <returns>In a Json Format</returns>  
        public JsonResult WelcomeNote()  
            bool isAdmin = false;  
            //TODO: Check the user if it is admin or normal user, (true-Admin, false- Normal user)  
            string output = isAdmin ? "Welcome to the Admin User" : "Welcome to the User";  
            return Json(output, JsonRequestBehavior.AllowGet);  

Get the list of users in JSON Format

/// <summary>  
/// Update the user details  
/// </summary>  
/// <param name="usersJson">users list in JSON Format</param>  
/// <returns></returns>  
public JsonResult UpdateUsersDetail(string usersJson)  
    var js = new JavaScriptSerializer();  
    UserModel[] user = js.Deserialize<UserModel[]>(usersJson);  
    //TODO: user now contains the details, you can do required operations  
    return Json("User Details are updated");  


ASP.NET MVC exception : Multiple types were found that match the controller named ‘Home’

This error message often happens when you use areas and you have the same controller name inside the area and the root. For example you have the two:


In order to resolve this issue (as the error message suggests you), you could use namespaces when declaring your routes. So in the main route definition in Global.asax:

    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Controllers" }

and in your ~/Areas/Admin/AdminAreaRegistration.cs:

    new { action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Areas.Admin.Controllers" }

If you are not using areas it seems that your both applications are hosted inside the same ASP.NET application and conflicts occur because you have the same controllers defined in different namespaces. You will have to configure IIS to host those two as separate ASP.NET applications if you want to avoid such kind of conflicts. Ask your hosting provider for this if you don’t have access to the server.

References :

How to add JavaScript library in MVC project

JavaScript :

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(


bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(

References :

Keywords : 

References ,  Script , Bundle