繁体   English   中英

将值从下拉列表传递给html actionlink mvc4 razor

[英]pass value from dropdown to html actionlink mvc4 razor

我试图将值从下拉列表传递到现有链接,但似乎没有任何工作:

index.cshtml:

@Html.ActionLink("Download", "MyDownload", null, new { @class = "button" })  
@Html.DropDownList("schools", "-- All Schools --")  

在我的SchoolsController中:

public FileContentResult MyDownload(string school="")
{
    List1<>
    List2<>

    var vals = 
         from list1
         join list2
         from
         select new {
             };

    if(school ! ="")
    {
        vals.where(x.list2.schools==school).tolist(); **// I get this error: "Object reference not set to an instance of an object."**
    }    
}

我可以在其他语言中轻松完成,我发现学习C#MVC需要永远。

您可以使用jQuery监视下拉列表中的更改事件。 现在,我不完全确定您是否尝试更改用于链接的文本或链接的实际href。 下面我创建了一些代码来改变它们。

视图

$(document).ready(function () {
    $("#schools").change(function () {
        var selection = $("#schools").val();
        var link = $("#Download");

        //Change text
        link.text(selection);

        //Change href
        link.attr("href", "linkHref" + selection)
    });
});

它看起来像这样,等待你想要处理你的链接和下拉列表的选择。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM