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. Image for the cookie policy date

Assign value to Textbox & datepicker from Model

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>


1 Reply

AB Ashokkumar Balasubramanian Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon