我需要將用戶輸入傳遞給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