Asp.net mvc 4 MVC4日期选择器';s所选值未设置为模型

Asp.net mvc 4 MVC4日期选择器';s所选值未设置为模型,asp.net-mvc-4,datepicker,Asp.net Mvc 4,Datepicker,我有DatePicker,我可以选择DatePicker的值,我被设置为TextBox,但我无法进入模型,它显示为空 我的约会选择人来了 @Html.TextBoxFor(model => model.CallDetailModel.CallDate, new { id = "callDate" }) 我的JavaScript在这里 @section Scripts { <script> $("#callDate").datepicker({

我有DatePicker,我可以选择DatePicker的值,我被设置为TextBox,但我无法进入模型,它显示为空

我的约会选择人来了

@Html.TextBoxFor(model => model.CallDetailModel.CallDate, new { id = "callDate" })
我的JavaScript在这里

@section Scripts {
    <script>
        $("#callDate").datepicker({
            changeMonth: true,
            changeYear: true
        });

</script>
}
我的CallDate属性是这样的

public DateTime? CallDate { get; set; }
一旦我点击提交按钮,我就无法获得日期的选定值 它显示空值

我的
创建操作
在这里

    [HttpPost]
    public ActionResult Create(CallModels model)
    {
        CallDetail obj = new CallDetail();
        obj.AccompaniedBy = model.CallDetailModel.AccompaniedBy;
        obj.BudgetFrom = model.CallDetailModel.BudgetFrom;
        obj.BudgetTo = model.CallDetailModel.BudgetTo;
        obj.CallCategory = model.CallDetailModel.CallCategory;
        obj.CallDate = model.CallDetailModel.CallDate;
        obj.CallDescription = model.CallDetailModel.CallDescription;
        obj.CallDuration = model.CallDetailModel.CallDuration;
        obj.CallTime = model.CallDetailModel.CallTime;
        obj.CallType = model.CallDetailModel.CallType;
        obj.ContactDetailId = model.CallDetailModel.ContactDetailId;
        obj.Id = model.CallDetailModel.ContactDetailId;
        obj.InquirySerialNo = model.CallDetailModel.InquirySerialNo;
        obj.Priority = model.CallDetailModel.Priority;
        obj.ProjectName = model.CallDetailModel.ProjectName;
        obj.PropertySerialNo = model.CallDetailModel.PropertySerialNo;
        obj.PurposeOfCall = model.CallDetailModel.PurposeOfCall;
        obj.Reference = model.CallDetailModel.Reference;
        obj.Reminder = model.CallDetailModel.Reminder;
        obj.Result = model.CallDetailModel.Result;
        obj.Tag = model.CallDetailModel.Tag;
        obj.ContactDetail = null;
        obj.IsActive = true;

        if (ModelState.IsValid)
        {
            myChannelFactory = new ChannelFactory<IBuilderTrackerServices>(myBinding, myEndpoint);
            // Create a channel.
            IBuilderTrackerServices wcfClientProperty = myChannelFactory.CreateChannel();
            var modelResult = wcfClientProperty.CreateCall(obj);
            ((IClientChannel)wcfClientProperty).Close();
            if (modelResult)
                return RedirectToAction("~/Views/CRM/Call/Index.cshtml");
        }
        return View(obj);
    }
[HttpPost]
公共操作结果创建(CallModels模型)
{
CallDetail obj=新的CallDetail();
obj.companiedby=model.CallDetailModel.companiedby;
obj.BudgetFrom=model.CallDetailModel.BudgetFrom;
obj.BudgetTo=model.CallDetailModel.BudgetTo;
obj.CallCategory=model.CallDetailModel.CallCategory;
obj.CallDate=model.CallDetailModel.CallDate;
obj.CallDescription=model.CallDetailModel.CallDescription;
obj.CallDuration=model.CallDetailModel.CallDuration;
obj.CallTime=model.CallDetailModel.CallTime;
obj.CallType=model.CallDetailModel.CallType;
obj.ContactDetailId=model.CallDetailModel.ContactDetailId;
obj.Id=model.CallDetailModel.ContactDetailId;
obj.InquirySerialNo=model.CallDetailModel.InquirySerialNo;
obj.Priority=model.CallDetailModel.Priority;
obj.ProjectName=model.CallDetailModel.ProjectName;
obj.PropertySerialNo=model.CallDetailModel.PropertySerialNo;
obj.PurposeOfCall=model.CallDetailModel.PurposeOfCall;
obj.Reference=model.CallDetailModel.Reference;
obj.rementer=model.CallDetailModel.rementer;
obj.Result=model.CallDetailModel.Result;
obj.Tag=model.CallDetailModel.Tag;
obj.ContactDetail=null;
obj.IsActive=true;
if(ModelState.IsValid)
{
myChannelFactory=新的ChannelFactory(myBinding,myEndpoint);
//创建一个频道。
IBuilderTrackerServices wcfClientProperty=myChannelFactory.CreateChannel();
var modelResult=wcfClientProperty.CreateCall(obj);
((IClientChannel)wcfClientProperty.Close();
if(modelResult)
返回重定向到操作(“~/Views/CRM/Call/Index.cshtml”);
}
返回视图(obj);
}
我不知道会出什么问题。。?
谢谢。

天哪,这是一个多么棒的代码。。。我不知道你想做什么,但绑定看起来不错,我不知道为什么你的日期是空的

要解决这个问题:

  • 确保输入文本框位于表单标记中
  • 将表单集合参数添加到操作中,并尝试在调试模式下检查它

    公共操作结果创建(CallModels模型、FormCollection表单)

  • 确保没有为DateTime定义自定义modelbinder

  • 确保日期格式正确。尝试将字段类型从DateTime更改为string,并检查结果
  • 但是您的代码还有许多其他问题。试着做一些像

       [HttpPost]
    public ActionResult Create(CallModels model)
    {       
        if (ModelState.IsValid) //to validate the detail only if(TryValidateModel(model.CallDetailModel))
        {
            myChannelFactory = new ChannelFactory<IBuilderTrackerServices>(myBinding, myEndpoint);
            // Create a channel.
            IBuilderTrackerServices wcfClientProperty = myChannelFactory.CreateChannel();
            var modelResult = wcfClientProperty.CreateCall(model.CallDetailModel); //dont create the new detail object, just get it from model.
            ((IClientChannel)wcfClientProperty).Close();
            if (modelResult)
                return RedirectToAction("Index");//redirect to anction - not to view.
        }
        return View(model); //!!!!! return your model to a same page not an obj
    }
    
    [HttpPost]
    公共操作结果创建(CallModels模型)
    {       
    if(ModelState.IsValid)//仅当(TryValidateModel(model.CallDetailModel))时验证详细信息
    {
    myChannelFactory=新的ChannelFactory(myBinding,myEndpoint);
    //创建一个频道。
    IBuilderTrackerServices wcfClientProperty=myChannelFactory.CreateChannel();
    var modelResult=wcfClientProperty.CreateCall(model.CallDetailModel);//不要创建新的细节对象,只需从模型中获取它即可。
    ((IClientChannel)wcfClientProperty.Close();
    if(modelResult)
    return RedirectToAction(“Index”);//重定向到anAction-不查看。
    }
    返回视图(模型);//!!!!!将模型返回到同一页面,而不是obj
    }
    
    显示您的操作(POST) code@maxs87我已经添加了我的创建操作..很抱歉,这不是您在上述表单中提到的有效格式,因为如果您发送model.CallDetailModel,则我无法插入新记录其所需的CallDetail obj,否则现在允许添加..第二个问题仍然是我的日期问题保持不变..我不知道您添加了什么日期。。。?
       [HttpPost]
    public ActionResult Create(CallModels model)
    {       
        if (ModelState.IsValid) //to validate the detail only if(TryValidateModel(model.CallDetailModel))
        {
            myChannelFactory = new ChannelFactory<IBuilderTrackerServices>(myBinding, myEndpoint);
            // Create a channel.
            IBuilderTrackerServices wcfClientProperty = myChannelFactory.CreateChannel();
            var modelResult = wcfClientProperty.CreateCall(model.CallDetailModel); //dont create the new detail object, just get it from model.
            ((IClientChannel)wcfClientProperty).Close();
            if (modelResult)
                return RedirectToAction("Index");//redirect to anction - not to view.
        }
        return View(model); //!!!!! return your model to a same page not an obj
    }