Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

MVC 5 controller return json value to view

// mvc controller
 [HttpPost]
        public ActionResult IndChecking(string dta, string isChk)
        {
          /////
           return this.Json (new { Data = result, cKey = ContainerKey }, JsonRequestBehavior.AllowGet);
        }

// view
    success: function (result) {
          alert(result.cKey);
          
    }
Comment

how to return json data from mvc controller to view

When you do return Json(...) you are specifically telling MVC not to use a view, and to serve serialized JSON data. Your browser opens a download dialog because it doesn't know what to do with this data.

If you instead want to return a view, just do return View(...) like you normally would:

var dictionary = listLocation.ToDictionary(x => x.label, x => x.value);
return View(new { Values = listLocation });
Then in your view, simply encode your data as JSON and assign it to a JavaScript variable:

<script>
    var values = @Html.Raw(Json.Encode(Model.Values));
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert date format from yyyy-mm-dd to dd-mm-yyyy using value javascript 
Javascript :: convert number to word crore/lakhs 
Javascript :: set js 
Javascript :: nodejs fs root folder path 
Javascript :: express response setTimeout 
Javascript :: json-server npm 
Javascript :: how to list node process 
Javascript :: convert result of .innerHTML to number on javascript 
Javascript :: javascript array add end 
Javascript :: javascript onload complete 
Javascript :: ajax code 
Javascript :: nodejs binary string to decimal number 
Javascript :: regular expression for thousand separator 
Javascript :: page redirect after load 
Javascript :: iterate over list array in solidity 
Javascript :: infinity javascript 
Javascript :: download a file nodejs 
Javascript :: react conditionally disable button 
Javascript :: javascript string in string 
Javascript :: ionic capacitor keyboard push content up 
Javascript :: check to see if work is uppercase javascript 
Javascript :: text field material ui max input for number 
Javascript :: browserslisterror contains both .browserslistrc and package.json with browsers 
Javascript :: Not allowed to navigate top frame to data URL 
Javascript :: get client id socket io 
Javascript :: loop through javascript object 
Javascript :: jsonarray add jsonobject 
Javascript :: preload javascript 
Javascript :: javascript loop over the alphabet and return the vowels 
Javascript :: react.fragment react native 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =