如何保持DropDownList的选定值后回传 [英] How to keep dropdownlist selected value after postback

查看:104
本文介绍了如何保持DropDownList的选定值后回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net MVC3如何保持项下拉列表回发后选定的。

In asp.net mvc3 how to keep dropdown list selected item after postback.

推荐答案

更​​容易,你可以在你的ActionResult输入参数包括你的下拉列表中的姓名(或名称)。您的下拉菜单应该在表单标签。当的ActionResult发布到,ASP.Net将通过查询字符串,表单值和饼干迭代。只要你包括你的名字下拉列表中,选择的值将是preserved。

Even easier, you can include the name(s) of your dropdowns in your ActionResult input parameters. Your dropdowns should be in form tags. When the ActionResult is posted to, ASP.Net will iterate through querystrings, form values and cookies. As long as you include your dropdown names, the selected values will be preserved.

在这里,我有3下拉菜单的职位,以一个ActionResult的形式。下拉名(不区分大小写):REPORTNAME,Year和Month

Here I have a form with 3 dropdowns that posts to an ActionResult. The dropdown names are (non-case sensitive): ReportName, Year, and Month.

    //MAKE SURE TO ACCEPT THE VALUES FOR REPORTNAME, YEAR, AND MONTH SO THAT THEY PERSIST IN THE DROPDOWNS EVEN AFTER POST!!!!
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ReportSelection(string reportName, string year, string month)
    {
        PopulateFilterDrowdowns();
        return View("NameOfMyView");
    }

这篇关于如何保持DropDownList的选定值后回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆