我需要将用户输入传递给url。 我CourseController操作是:在url中传递用户输入
public ActionResult Parameter(DateTime start, DateTime end)
{
//some operations
return View();
}
我从在我看来,用户得到的开始和结束时间。 我想看到这样的网址:课程/参数/开始=用户输入& &结束= userinput 任何帮助,将不胜感激。
My model is:
public class MachineSql{
public List<Machines> SqlAccessParameter(DateTime startDate, DateTime endDate)
{
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;
}}
当你说“我从用户的角度看我的开始和结束”时,你的意思是使用表单提交它吗? – tomasmcguinness 2013-02-15 14:14:01
@tomasmcguinness是的,它使用这样的表单提交:@using(ajax.beginform('ActionName','ControllerName')) – pln 2013-02-15 14:41:01
为什么你想要通过URL传递的值? – tomasmcguinness 2013-02-15 14:48:35