博客
关于我
asp.net mvc SelectList 的selected 失效及解决方案
阅读量:451 次
发布时间:2019-03-06

本文共 452 字,大约阅读时间需要 1 分钟。

在ASP.NET MVC的强类型视图中,下拉列表的选择项在View上失效的问题可能与ViewData和SelectList的名称冲突有关。以下是解决问题的详细步骤:

  • 分析Controller代码:确认Action方法是否正确设置了SelectList的初始值和绑定信息。确保ViewData中的键名与SelectList的Name属性不冲突。

  • 检查View代码:在强类型视图中,确保DropDownList的Name属性与从ViewData中获取的键名不同。例如,若ViewData中使用的是ddlDataSysid作为键,则DropDownList的Name应改为ddlSysid

  • 修改View代码

    这样,DropDownList的Name为ddlSysid,而ViewData中的键为ddlDataSysid,避免了冲突。

  • 测试和验证:提交表单,检查是否能够正确获取到选中的值,并确保数据绑定到正确的变量中。

  • 通过以上步骤,可以解决下拉列表在View上选中失效的问题,确保数据能够正确传递和绑定。

    转载地址:http://ydifz.baihongyu.com/

    你可能感兴趣的文章
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No static resource favicon.ico.
    查看>>
    no such file or directory AndroidManifest.xml
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    node exporter完整版
    查看>>
    node HelloWorld入门篇
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node JS: < 二> Node JS例子解析
    查看>>
    Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime(93)解决
    查看>>
    Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
    查看>>