jsonresult

How can I return a Dictionary<string, Object> as JsonResult, AND get the proper result in JavaScript?

被刻印的时光 ゝ 提交于 2019-12-01 06:45:07
I'm constructing my JsonResult in Controller by adding some extra information to an already existing JsonResult (returned from a different method). In order to add more properties, I converted the initial JsonResult into a Dictionary: IDictionary<string, object> wrapper = (IDictionary<string, object>)new System.Web.Routing.RouteValueDictionary(json.Data); Then I just add data by writing wrapper["..."] = "value" . The method returns a new JsonResult, with wrapper as .Data: new JsonResult() { wrapper, JsonRequestBehavior.AllowGet }; and that's where the troubles start; while communication

How can I return a Dictionary<string, Object> as JsonResult, AND get the proper result in JavaScript?

放肆的年华 提交于 2019-12-01 05:45:57
问题 I'm constructing my JsonResult in Controller by adding some extra information to an already existing JsonResult (returned from a different method). In order to add more properties, I converted the initial JsonResult into a Dictionary: IDictionary<string, object> wrapper = (IDictionary<string, object>)new System.Web.Routing.RouteValueDictionary(json.Data); Then I just add data by writing wrapper["..."] = "value" . The method returns a new JsonResult, with wrapper as .Data: new JsonResult() {

calling @Html.Action for JsonResult changes my response type in parent template

こ雲淡風輕ζ 提交于 2019-12-01 03:27:12
I've got the following controller: public class HelloController { public ActionResult Index() { return View() } public ActionResult Hello() { return Json(new{ greeting = "hello, world!" }, JsonRequestBehavior.AllowGet); } } Then, inside Index.cshtml : ...html stuffs <script type="text/javascript"> alert("@Html.Action("Hello")"); </script> What I'm finding is that, when going to this url in my browser, the response content type is application/json; charset=utf-8 which causes the browser to render the html as a string instead of as... a web page. What's the best way to get around this? The

calling @Html.Action for JsonResult changes my response type in parent template

落花浮王杯 提交于 2019-11-30 23:09:21
问题 I've got the following controller: public class HelloController { public ActionResult Index() { return View() } public ActionResult Hello() { return Json(new{ greeting = "hello, world!" }, JsonRequestBehavior.AllowGet); } } Then, inside Index.cshtml : ...html stuffs <script type="text/javascript"> alert("@Html.Action("Hello")"); </script> What I'm finding is that, when going to this url in my browser, the response content type is application/json; charset=utf-8 which causes the browser to

Returning JSON from a JsonResult method in MVC controller

可紊 提交于 2019-11-30 19:40:42
I am trying to populate a ComboBox (Telerik RAD COmboBox) in a test ASP.NET MVC3 app. I have defined the ComboBox on my ASPX page and in the controller I have defined the action call that returns a JsonResult. The problem I am having is that the Web Service I am using already returns the resultset as a JSON string. How can I pass the response from the Webservice directly. Here is the snippets of code: ASPX page: <% Html.Telerik().ComboBox() .Name("cbRefTables") .DataBinding(b => b .Ajax() .Select("GetCALMdata","Common") ) .Render(); %> Controller: called CommomController public JsonResult

Returning JSON from a JsonResult method in MVC controller

旧街凉风 提交于 2019-11-30 03:23:22
问题 I am trying to populate a ComboBox (Telerik RAD COmboBox) in a test ASP.NET MVC3 app. I have defined the ComboBox on my ASPX page and in the controller I have defined the action call that returns a JsonResult. The problem I am having is that the Web Service I am using already returns the resultset as a JSON string. How can I pass the response from the Webservice directly. Here is the snippets of code: ASPX page: <% Html.Telerik().ComboBox() .Name("cbRefTables") .DataBinding(b => b .Ajax()

How to redirect to a controller action from a JSONResult method in ASP.NET MVC?

江枫思渺然 提交于 2019-11-29 21:28:10
I am fetching records for a user based on his UserId as a JsonResult... public JsonResult GetClients(int currentPage, int pageSize) { if (Session["UserId"] != "") { var clients = clirep.FindAllClients().AsQueryable(); var count = clients.Count(); var results = new PagedList<ClientBO>(clients, currentPage - 1, pageSize); var genericResult = new { Count = count, Results = results }; return Json(genericResult); } else { //return RedirectToAction("Index","Home"); } } How to redirect to a controller action from a JsonResult method in asp.net mvc?Any suggestion... EDIT: This doesn't seem to work...

Sorting not working with Json Result giving encoded output

人走茶凉 提交于 2019-11-29 16:22:27
I am using Json Result to show a table, it is working fine when I show the result. Now I wanted to add a sort feature to it, so I used the canSort:true property. But now whenver I click on the header of the table for the sort to happen I get the below encoded string in my browser, it seems it is sorted too but some kind of encoding is done to it, it is as below. {"Data":"\u003ctable class=\"paramCustomDataTable\"\u003e\u003cthead\u003e\u003ctr class=\"customHead\"\u003e\u003cth scope=\"col\"\u003e\u003ca href=\"/Parameters/CustomData?id=7&sort=Name&sortdir=ASC\"\u003eName\u003c/a\u003e\u003c

JsonResult return Json in ASP.NET CORE 2.1

痴心易碎 提交于 2019-11-29 09:10:59
Controller that worked in ASP.NET Core 2.0: [Produces("application/json")] [Route("api/[controller]")] [ApiController] public class GraficResourcesApiController : ControllerBase { private readonly ApplicationDbContext _context; public GraficResourcesApiController(ApplicationDbContext context) { _context = context; } [HttpGet] public JsonResult GetGrafic(int ResourceId) { var sheduling = new List<Sheduling>(); var events = from e in _context.Grafic.Where(c=>c.ResourceId == ResourceId) select new { id = e.Id, title = e.Personals.Name, start = e.DateStart, end = e.DateStop, color = e.Personals

ASP.Net MVC: how to create a JsonResult based on raw Json Data

天涯浪子 提交于 2019-11-29 04:03:47
Having a string containing the following raw Json data (simplified for the sake of the question): var MyString = "{ 'val': 'apple' }"; How can I create a JsonResult object representing MyString ? I tried to use the Json(object) method. but it handles the raw json data as an string -logically :P-. So the returned HTTP response looks like: "{ 'val': 'apple' }" instead of the given raw Json Data: { 'val': 'apple' } this is what I want to achieve : Brant Bobby The Json() method on Controller is actually a helper method that creates a new JsonResult . If we look at the source code for this class *