简体   繁体   中英

standard textbox doesn't get default DateTime value

I'm currently building an MVC c# application and I can't seem to find the solution for this. I'm guessing it's something silly. It's a bit of a simplified example I'm telling right now, but it's accurate. I have a strongly modelled View, @model xxx.Store and in there I show a table of items, Fruit models . Now each table entry has an expire date. I use JQuery's Datepicker for UI friendly datepicking, but I have trouble setting the default value in that textbox for an existing value. I know the data gets saved, I see so in my database, but it doesn't show on the web page.

@foreach(var item in ...)
    ...
    <input type="text" onchange="updateExpireDate(this.value, @item.LoginID);" 
                       class="datepick" value="@item.ExpireDate.ToString()" />  
    ...

So basically the value part, doesn't work. I've thought about using Html.TextboxFor(...) but that points to my central modal, the Store class, which I'm not using in that table.

Also might be important to note, the ExpireDate value is nullable. No exceptions are thrown in Visual Studio or Chrome's Dev Tools

Try Html.TextBox

@Html.TextBox("txtName", "Mairaj Ahmed  ", new {class="datepick",onchange="updateExpireDate(this.value, @item.LoginID);" });

Here "Mairaj Ahmed" is value of textbox you can change it to model property. And attributes will be added with new keyword separated by comma.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM