Possible bug in ASP.NET MVC with form values being replaced

后端 未结 12 688
抹茶落季
抹茶落季 2020-11-29 00:41

I appear to be having a problem with ASP.NET MVC in that, if I have more than one form on a page which uses the same name in each one, but as different types (radio/hidden/e

12条回答
  •  暖寄归人
    2020-11-29 00:58

    This may be 'by design' but it's not what is documented:

    Public Shared Function Hidden(  
    
      ByVal htmlHelper As System.Web.Mvc.HtmlHelper,  
      ByVal name As String, ByVal value As Object)  
    As String  
    

    Member of System.Web.Mvc.Html.InputExtensions

    Summary: Returns a hidden input tag.

    Parameters:
    htmlHelper: The HTML helper.
    name: The form field name and System.Web.Mvc.ViewDataDictionary key used to look up the value.
    value: The value of the hidden input. If null, looks at the System.Web.Mvc.ViewDataDictionary and then System.Web.Mvc.ModelStateDictionary for the value.

    This would seem to suggest that ONLY when the value parameter is null (or not specified) would the HtmlHelper look elsewhere for a value.

    In my app, I've got a form where: html.Hidden("remote", True) is rendering as

    Note the value is getting over-ridden by what is in the ViewData.ModelState dictionary.

    Or am I missing something?

提交回复
热议问题