且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在控制器页面中获取选择标记值?

更新时间:2023-11-24 13:00:46

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



例如

< 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.