我的Actionlink无效请帮助
<div data-role="select">
<select id="js-data-example-ajax" name="js-data-example-ajax">
@foreach (var item in Model)
{
<option value=" 3620194">
@Html.ActionLink(@item.ProductName, "GetByID", new { Area = "Common", ID = item.ProductID })
</option>
}
</select>
</div>
OR
<div data-role="select">
<select id="js-data-example-ajax" name="js-data-example-ajax">
@foreach (var item in Model)
{
<option value=" 3620194">
@Ajax.ActionLink(@item.ProductName, "GetByID", new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "js-data-example-ajax", InsertionMode = InsertionMode.ReplaceWith })
</option>
}
</select>
</div>
在Home Controller中,动作链接不在GetByID方法
上 public ViewResult GetByID(string ID)
{
return View();
}
答案 0 :(得分:1)
option
元素内的链接不会呈现为链接。相反,你需要自己处理点击,例如使用jQuery。你可以这样做:
<div data-role="select">
<select id="js-data-example-ajax" name="js-data-example-ajax">
@foreach (var item in Model)
{
<option value="3620194" data-url="@Url.Action("GetByID", new { Area = "Common", ID = item.ProductID })">
@item.ProductName
</option>
}
</select>
</div>
<script type="text/javascript">
$(function () {
$('#js-data-example-ajax').on('change', function() {
var url = $('#js-data-example-ajax').find(":selected").data('url');
document.location = url;
});
});
</script>