如何在控制器页面中获取选择标记值? [英] how will I get select tag value in controller page?

查看:117
本文介绍了如何在控制器页面中获取选择标记值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@ Html.LabelFor(model => model.AlbumId,Please Album Name)

@ Html.DropDownListFor(m => m.albums,Model.albums,Please Select ,new {@id =albums,@ class =state,@ onchange =javascript:GetSongs(this.value);})





@ Html.LabelFor(model => model.SongId,请选择歌曲)



< select id =ddlsongs name =ddlsongsclass =state>< / select>





< input name =songname type =submitclass =button1value =点击生成链接/>

解决方案

我认为你可以在控制器中使用表单集合参数你的所有控制值都来自控制器。



例如

< br /> 
Public ActionResult test(FormCollection集合)< br />
{< br />
//您可以获得任何值,例如< br />
collection [input]< br />
< br />
}


您还可以在控制器中添加一个带有select标签名称的参数,例如

  public  ActionResult Save( string  ddlsongs)
{
// 您的代码在这里......
}



其中ddlsongs是您问题中的选择标记的名称。

@Html.LabelFor(model => model.AlbumId, "Please Album Name")
@Html.DropDownListFor(m => m.albums, Model.albums, "Please Select", new { @id = "albums", @class = "state", @onchange = "javascript:GetSongs(this.value);" })


@Html.LabelFor(model => model.SongId, " Please Select Song ")

<select id="ddlsongs" name="ddlsongs" class="state" ></select>


<input name="songname" type="submit" class="button1" value="Click to generate link"/>

解决方案

I think you can use form collection parameter in controller in which your all controls value comes at controller.

e.g.

<br />
Public ActionResult test(FormCollection collection)<br />
{<br />
//you can get any value like <br />
collection["input"]<br />
<br />
}


You can also add a parameter with the name of select tag in your controller like so

public ActionResult Save(string ddlsongs)
{
    //Your code here...
}


where ddlsongs is the name of select tag like the one in your question.


这篇关于如何在控制器页面中获取选择标记值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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