Does Html.TextBox uses Request.Params instead of Model?

后端 未结 3 1020
时光取名叫无心
时光取名叫无心 2021-01-13 02:25

I have a simple test application:

Model:

public class Counter
{
    public int Count { get; set; }

    public Counter()
    {
        Count = 4;
           


        
3条回答
  •  春和景丽
    2021-01-13 03:10

    That's not the issue here. Specifying

    <%= Html.TextBox("Count") %>
    

    is equivalent to specifying

    <%= Html.TextBox("Count", null) %>
    

    which will pull the matching value (named "Count") from the ModelStateDictionary.

    But even so, explicitly passing in

    <%= Html.TextBox("Count", Model.Count) %>
    

    results in the same behavior described by alex2k8.

提交回复
热议问题