如果我点击 添加日期 begin_date , end_date 将添加到我的视图中。一开始我只有1个开始和结束日期。使用以下内容添加日期:
$(document).ready(function () {
var str = '<div class="form-group">' +
'@Html.LabelFor(model => model.begin_date, new { @class = "control-label col-md-2" })' +
'<div class="col-md-10">' +
' @Html.TextBoxFor(model => model.begin_date, new { @Value = ViewBag.startDate, id = "begin_date" })' +
' @Html.ValidationMessageFor(model => model.begin_date)' +
'</div>' +
' </div>' +
' <div class="form-group">' +
' @Html.LabelFor(model => model.end_date, new { @class = "control-label col-md-2" })' +
' <div class="col-md-10">' +
' @Html.TextBoxFor(model => model.end_date, new { id = "end_date", @Value = ViewBag.endDate })' +
' @Html.ValidationMessageFor(model => model.end_date)' +
' </div>' +
' </div>';
$("#addItem").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { $("#editorRows").append(str); }
});
return false;
});
});
在我的控制器中,我在帖子DateTime begin_date, DateTime end_date
上有参数,并且他们只接收第一个 begin_date 和 end_date 的值。我如何获得第一个 begin_date 和最后添加 end_date 的价值?
我的观点:pastebin
发布控制器:
[HttpPost]
public ActionResult Create(int merchantId, string name, DateTime begin_date, DateTime end_date)
{
ViewBag.startDate = DateTime.Now.AddDays(1).ToShortDateString();
ViewBag.endDate = DateTime.Now.AddMonths(1).ToShortDateString();
TmpUniPaySchedulesRowArray nameValuePairArray = new TmpUniPaySchedulesRowArray();
nameValuePairArray.TmpUniPaySchedulesRowArrayObj = new TmpUniPaySchedulesRow[1];
TmpUniPaySchedulesRow row = new TmpUniPaySchedulesRow();
row.Id = 0;
row.BeginDate = begin_date;
row.EndDate = end_date;
row.AmountPercentage = 100;
nameValuePairArray.TmpUniPaySchedulesRowArrayObj[0] = row;
Oracle.DataAccess.Client.OracleCommand oracleCommand = new Oracle.DataAccess.Client.OracleCommand(); //gasasworebelia!!!!!
oracleCommand.Connection = new Oracle.DataAccess.Client.OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleBillUser"].ConnectionString);
oracleCommand.CommandType = System.Data.CommandType.StoredProcedure;
oracleCommand.CommandText = "tmp_uni.pay_schedules_group_add";
oracleCommand.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("ai_merchant_id", Oracle.DataAccess.Client.OracleDbType.Int32, merchantId, System.Data.ParameterDirection.Input));
oracleCommand.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("ai_name", Oracle.DataAccess.Client.OracleDbType.Varchar2, name, System.Data.ParameterDirection.Input));
oracleCommand.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("ai_begin_date", Oracle.DataAccess.Client.OracleDbType.Date, begin_date, System.Data.ParameterDirection.Input));
oracleCommand.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("ai_end_date", Oracle.DataAccess.Client.OracleDbType.Date, end_date, System.Data.ParameterDirection.Input));
Oracle.DataAccess.Client.OracleParameter paramPayerInputData = new Oracle.DataAccess.Client.OracleParameter("ai_pay_schedules_values", Oracle.DataAccess.Client.OracleDbType.Array, nameValuePairArray, System.Data.ParameterDirection.Input);
paramPayerInputData.UdtTypeName = "TMP_UNI_PAY_SCHEDULES_TYPE"; //case sensitive!!!
oracleCommand.Parameters.Add(paramPayerInputData);
oracleCommand.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("ao_error_code", Oracle.DataAccess.Client.OracleDbType.Int32, System.Data.ParameterDirection.Output));
if (oracleCommand.Connection.State == System.Data.ConnectionState.Closed)
oracleCommand.Connection.Open();
try
{
oracleCommand.ExecuteNonQuery();
int returnErrorCode = int.Parse(oracleCommand.Parameters["ao_error_code"].Value.ToString());
}
catch (OracleException ex)
{
Console.WriteLine(ex.ToString());
}
return RedirectToAction("Index");
}
答案 0 :(得分:2)
模型绑定使用您输入的名称;由于您要复制控件名称,请尝试更改方法以接受日期时间对象的集合:
public ActionResult Create(int merchantId, string name, IEnumerable<DateTime> begin_date, IEnumerable<DateTime> end_date)
你当然必须遍历这个以获得你自己的第一个/最后一个项目。
var firstBeginDate = begin_date.First();
var lastEndDate = end_date.Last();