更改MVC下拉列表时的商店价值 [英] Store value onchange of mvc dropdownlist

查看:70
本文介绍了更改MVC下拉列表时的商店价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想存储一个mvc dropdownlist onchange事件的选定值,以便以后使用.
在带注释的代码中,示例显示了选项及其编号的已知值.
在我的下拉列表中,我不知道值的数量,也不知道它们的值.

Hello
I want to store a selected value of an mvc dropdownlist onchange event in order to use it later.
In the commented code the example with known values of options and their number.
In my dropdown list I don''t know in advance the number of value neither their values.

<table width="150" border="0" cellspacing="0" cellpadding="0" style="margin-removed 1px; margin-removed 1px; margin-removed 1px;">
<tr>
           
<td class="formrechinp">
     <%= Html.DropDownList("localsites",
                                          SiteHelper.GetSitesList((CultureInfo) Session["Culture"],
                                                                  menuState.Site_Name),
                                          new {@class = "forminput"}) %>         
                                         
        </td>
    </tr>
</table>     
                                         
        
    


<%--
<select  style="width: 80px;
    border: 1px solid #78B1FF;">
    <option value="<%= PhonebookEP.Helpers.EnumTargetDirectory.Local %>" <% if(PhonebookEP.Helpers.EnumTargetDirectory.Local.Equals(Session["TargetDirectory"])) Response.Write(" selected=\"selected\"");%>>
        <%= ViewRes.SharedStrings.MenuDTLocal %></option>
    
</select>--%>

推荐答案

我了解您要使用选定的ddl值.
当您运行上述代码时,"localsites" ddl将呈现为元素.
因此,可以使用javascript捕获选定的值或文本以供页面使用(呈现).

如果要在服务器上使用该值;最快的方法是-
1.在控制器中有一个post方法-
[HttpPost]
ActionResult MyMethod(FormCollection项目){...}

2)将您的上一页源代码放入...您的以上代码中..



3)单击提交按钮后,它将数据发布到服务器,然后可以从MyMethod的项目中检索ddl的值.

几周后,我将发布一篇有关使用jQuery插件处理所有这些回发问题的文章. -sasi
I understand that you want to use the selected ddl value.
When you run above code the "localsites" ddl will be rendered as elements.
So, the selected value or text can be captured using javascript for the page(rendered) use.

If you want to use the value at server; the quickest way is -
1. Have a post method in controller -
[HttpPost]
ActionResult MyMethod(FormCollection items){...}

2)put your above page source inside the ...your above code..



3)When you click the submit button, it post the data to server then you can retrive the value of ddl from items of MyMethod.

In a couple of weeks I will be posting an article about using jQuery plugin to handle all these postback issues. - sasi


这篇关于更改MVC下拉列表时的商店价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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