Click here to Skip to main content
12,957,731 members (61,938 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,
I need to simply passed the json data which is created in controller to view (in a text area)
my codes are as follow:
My Model: Machines.cs
public class MachinesSql
   {
 
  public List<machines> SqlAccessParameter(DateTime startDate, DateTime endDate)
        {
             string connstr = "Data Source=USER-BILGISAYAR;Initial Catalog=Report;Integrated Security=True";
            SqlConnection myConnection = new SqlConnection(connstr);
            myConnection.Open();
            SqlCommand myCommand = new SqlCommand("DateRange",myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.Parameters.Add("@SP_startDate", SqlDbType.DateTime).Value = startDate;
            myCommand.Parameters.Add("@SP_endDate", SqlDbType.DateTime).Value = endDate;
                       
            SqlDataAdapter dataAdapter = new SqlDataAdapter();
            myCommand.ExecuteNonQuery();
            dataAdapter.SelectCommand = myCommand;
           
            DataSet dSet = new DataSet();
            dataAdapter.Fill(dSet);
          
            myConnection.Close();
 
            List<machines> machinePost = new List<machines>();
            foreach (DataRow row in dSet.Tables[0].Rows)
            {
                Machines mac = new Machines();
                mac.AutoKey = (int)row["AUTOKEY"];
                mac.MachineGroup = (string)row["MACHINEGROUP"];
                mac.Duration = (int)row["DURATION"];
                mac.StartDate = (DateTime)row["STARTTIME"];
                mac.EndDate = (DateTime)row["ENDTIME"];
                machinePost.Add(mac);
            }
            return machinePost;
        }
}
My controller: MachinesController.cs
<pre lang="xml">public JsonResult Parameter(DateTime start, DateTime end)
       {
           MachinesSql a = new MachinesSql();
 
           var data = a.SqlAccessParameter(start, end);
           List<Machines> list = new List<Machines>(data);
         return Json(list);
       }//here I can get json data like:
[{"AutoKey":1,"MachineGroup":"Atyc","StartDate":"\/Date(1322002860000)\/","EndDate":"\/Date(1322027095000)\/","Duration":24235},{"AutoKey":2,"MachineGroup":"Fongs","StartDate":"\/Date(1322003160000)\/","EndDate":"\/Date(1322012194000)\/","Duration":9034},{"AutoKey":3,"MachineGroup":"Then","StartDate":"\/Date(1322005320000)\/","EndDate":"\/Date(1322019001000)\/","Duration":13681},{"AutoKey":4,"MachineGroup":"Numune","StartDate":"\/Date(1322008920000)\/","EndDate":"\/Date(1322031974000)\/","Duration":23053},{"AutoKey":5,"MachineGroup":"Then","StartDate":"\/Date(1322009760000)\/","EndDate":"\/Date(1322032624000)\/","Duration":22863},{"AutoKey":6,"MachineGroup":"Fongs","StartDate":"\/Date(1322010060000)\/","EndDate":"\/Date(1322067224000)\/","Duration":57163},{"AutoKey":7,"MachineGroup":"Fongs","StartDate":"\/Date(1322012220000)\/","EndDate":"\/Date(1322070357000)\/","Duration":58137},{"AutoKey":8,"MachineGroup":"Fongs","StartDate":"\/Date(1322012940000)\/","EndDate":"\/Date(1322026274000)\/","Duration":13334},{"AutoKey":9,"MachineGroup":"Then","StartDate":"\/Date(1322021640000)\/","EndDate":"\/Date(1322040622000)\/","Duration":18982},{"AutoKey":10,"MachineGroup":"Atyc","StartDate":"\/Date(1322023440000)\/","EndDate":"\/Date(1322032891000)\/","Duration":9450}]
 
My View:
@{
    ViewBag.Title = "Index";
   
}
   @using (Ajax.BeginForm("Parameter", "Machines", new AjaxOptions { UpdateTargetId = "text" }))    
{
   
<head>
    <title>Intro</title>
    
    <script src="~/Scripts/jquery-1.8.3.min.js"></script>
    <script src="~/Scripts/kendo/kendo.all.min.js"></script>
    <link href="~/Scripts/kendo/kendo.common.min.css" rel="stylesheet" />
    <link href="~/Scripts/kendo/kendo.default.min.css" rel="stylesheet" />
   
   </head>     
<body> 
  
    @*<div id="chart"></div>*@
    <div>
       
       Start Date:  <input type="datetime" id="start" name="start" />//start parameter related with  public JsonResult Parameter(DateTime start, DateTime end)
 
       End Date: <input type="datetime" id="end" name="end" />//start parameter related with  public JsonResult Parameter(DateTime start, DateTime end)
 
    </div>
     <input type="submit" value="OK" />
    
   <textarea id="text"></textarea>


I am waiting for ajax.beginform updateTargetId='text' updates textarea with id='text' but it could not update.How can I use result from controller in view??
any help would be appreciated.Thanks...
Posted 14-Feb-13 5:26am
pln474273
Updated 14-Feb-13 5:36am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,994
CHill60 3,550
Maciej Los 3,312
ppolymorphe 2,170
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100