We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Assign value to Textbox & datepicker from Model

Thread ID:

Created:

Updated:

Platform:

Replies:

146730 Aug 16,2019 09:32 AM UTC Aug 19,2019 12:56 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: DatePicker
Kenneth Tang
Asked On August 16, 2019 09:32 AM UTC

Dear all,
When we use model to pass the value into page which show as follow, it can't display the default value and the datepicker can't also be display.
Please advance, thx.
KennethT
[chtml]
@{ 
    @model HRCM.Master.Model.Staff
}
    <form asp-action="Create" asp-controller="Staff" method="post" asp-route-session="Staff">
        <div>
            <ejs-datetimepicker id="JOIN_DATE" placeholder="Select a date and time" ejs-for="@Model.JOIN_DATE" value="@Model.JOIN_DATE"></ejs-datetimepicker>
        </div>
        <div>
            <ejs-textbox id="GUID" name="GUID" placeholder="GUID" ejs-for="@Model.GUID"></ejs-textbox>
        </div>

            <div class="form-group">
                <input type="submit" value="Create Session" class="btn btn-primary" />
            </div>
        }
    </form>


Ashokkumar Balasubramanian [Syncfusion]
Replied On August 19, 2019 12:56 PM UTC

 
Hi Kenneth Tang, 
 
Good day to you. 
 
We have checked your code snippet and the cause of the problem is ejs-for component model value is bind to value property. So, no need to bind value property again. By default, datetimepicker default value is Null, we suspect you have use DateTime datatype, the DateTime default value set (12/31/2000 00:00). So, use nullable DateTime type (DatetTime?) and pass the current date or null. please find the code snippet and demos for your reference. 
 
<form method="post"> 
    <div> 
        <ejs-datetimepicker id="JOIN_DATE" placeholder="Select a date and time" ejs-for="@Model.JOIN_DATE" value="@Model.JOIN_DATE"></ejs-datetimepicker> 
    </div> 
    <div> 
        <ejs-textbox id="GUID" name="GUID" placeholder="GUID" ejs-for="@Model.GUID"></ejs-textbox> 
    </div> 
    <div class="form-group"> 
        <input type="submit" value="Create Session" class="btn btn-primary" /> 
    </div> 
</form> 
 
public class HomeController : Controller 
        { 
            Session valueObject = new Session(); 
            public IActionResult Index() 
            { 
                valueObject.JOIN_DATE = DateTime.Now; 
                valueObject.GUID = ""; 
                return View(valueObject); 
            } 
            [HttpPost] 
            public IActionResult Index(Session model) 
            { 
                valueObject.JOIN_DATE = model.JOIN_DATE; 
                return View(model); 
            } 
        } 
 
 
 
Please check the sample and get back to us if you need any further assistance. 
 
Regards, 
Ashokkumar B. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon