1

I have DatePicker I am able to selecte the value of DatePicker and I was set to TextBox but I am not able to get into model it show me null.?

my date picker is here

@Html.TextBoxFor(model => model.CallDetailModel.CallDate, new { id = "callDate" })

my JavaScript here

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

</script>
}

I have added theme and UI into _Layout after closing of footer and before end of body tag

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Styles.Render("~/Content/themes/base/css")
    @Scripts.Render("~/bundles/jquerymenu")
    @RenderSection("scripts", required: false)

my CallDate property like this

public DateTime? CallDate { get; set; }

once I click on submit button that time I am not able to get the selected value of date it show me null value.

My Create Action is here

    [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);
    }

what is going to wrong I don't know..? thank you.

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
Jitendra Jadav
  • 53
  • 1
  • 1
  • 9

1 Answers1

0

Omg what a code... I dont know what you trying to do but the binding looks right and i have no idea why your date is null.

To solve problem:

  1. Ensure that the input text box are in form tag.
  2. Add the form collection parameter to your action and try inspect it in debug mode.

    public ActionResult Create(CallModels model, FormCollection form)

  3. Ensure that the no custom modelbinder defined for DateTime.

  4. Ensure that the date has correct format.Try to change field type from DateTime to string and inspect result.

But you have many another problem with your code. try to do something like

   [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
}
maxs87
  • 2,274
  • 2
  • 19
  • 23
  • sorry to say this is not valid format what you had mention in above form because if you send model.CallDetailModel then I am not able to Insert new record its required CallDetail obj otherwise it is now allow to add.. – Jitendra Jadav Jun 17 '13 at 12:15
  • and second is still my date problem remain same...I don't know what you added for date...? – Jitendra Jadav Jun 17 '13 at 12:15