Skip to content Skip to sidebar Skip to footer

Passing Controller Json Result To View

I need to simply passed the json data which is created in controller to view my codes are as follow: My Model: Machines.cs In my model I get the dates as a string and parse them t

Solution 1:

You could access it via your Model or make an AJAX request to the Parameter action in your controller. I have rewrote your Parameter Action to return the View and use the MachinesSql as the model:

public ActionResult Parameter()
{
   MachinesSql model = new MachinesSql();

   return View("YourViewName", model);
}

Then in your view you could do:

@Model MachinesSql

foreach(var m in @Model.SqlAccessParameter(startDate, endDate)) {
    @Html.DisplayFor(m=>m.DataValue);
}

Edit: Showing how to achieve via an AJAX Call

functionCallAjaxFunction() {
     var sDate = document.getElementById('start');
     var eDate = document.getElementById('end');

     $.ajax{({
         url: '@Url.Action("Parameter")',
         data: { startDate: sDate, endDate: eDate },
         type: "POST",
         success: function(content) { 
            alert(content);
         }
     }); 
}

Post a Comment for "Passing Controller Json Result To View"