我如何在选项标签 asp.net mvc 5 中使用 html.actionlink 或 ajax.action

How can i use html.actionlink or ajax.action in option tag asp.net mvc 5

我的操作link不工作请帮助

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

   <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 操作中 link 未使用 GetByID 方法

    public ViewResult GetByID(string ID)
    {
       return View();
    }

option 元素内的链接不会呈现为 link。相反,您需要自己处理点击,例如 jQuery。你可以这样做:

HTML

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

jQuery

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