传递模型参数进行查看 [英] passing model parameters to view

查看:70
本文介绍了传递模型参数进行查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我需要传递模型参数才能查看。

我的模型类是:Machines.cs

Hi!
I need to pass model parameters to view.
My Model class is: Machines.cs

public class Machines
    {
        [Key]
        public int AutoKey;
        public string MachineGroup;
        public DateTime StartDate;
        public DateTime EndDate;
        public int Duration;
        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;
        }
        
    
    }



我的控制器:MachinesController


My controller: MachinesController

public ActionResult MachineParameter()
     {
         Machines model = new Machines();

         return View(model);
     }









我需要用户输入( startDate和endDate)指定日期范围。所以在我看来必须使用SqlAccessParameter(DateTime startDate,DateTime endDate)方法,这个startDate和endDate参数必须来自用户bur我不知道如何才能实现这一点。任何帮助将不胜感激,谢谢提前。





I need to user input (startDate and endDate) to specify date range. So in my view SqlAccessParameter(DateTime startDate, DateTime endDate) method must be used and this startDate and endDate parameters must be came from users bur I don''t know how can I achieve this. Any help would be appreciated, thanks in advance.

推荐答案

这里就像这一行



@Html。 Telerik()。DateTimePickerFor(a => a.StartDate,new {@class =input-small})
here like this line

@Html.Telerik().DateTimePickerFor(a => a.StartDate, new { @class = "input-small" })


这篇关于传递模型参数进行查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆