Html.TextboxFor default value for Integer/Decimal to be Empty instead of 0

后端 未结 8 2285
谎友^
谎友^ 2020-12-08 06:36

I am using the default asp.net MVC 2 syntax to construct TextBox\'s which are integer or decimal for my asp.net MVC web app:

<%: Html.TextBoxFor(model =&g         


        
相关标签:
8条回答
  • 2020-12-08 07:05

    You can override the default template by putting a custom template in /Shared/EditorTemplates or by controller in /ControllerName/EditorTemplates.

    I use this one for Int's. Its named Int32.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    <%@ Import Namespace="System.Web.Mvc.Html" %>
    <%
        string displayText = string.Empty;
    
        if (Model != null)
        {
            displayText = Model.ToString();
        }
    
    %>
    
    <%= Html.TextBox("", displayText)%>
    
    0 讨论(0)
  • 2020-12-08 07:07

    I use this solution :

       @Html.TextBoxFor(model => model.Year, new { Value = "" })
    

    refer to : https://stackoverflow.com/a/6186576/297487

    0 讨论(0)
提交回复
热议问题