我正在尝试Ajax.ActionLink
在 HTML 选择选项中嵌入如下
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"</script>
<select>
<option>@Ajax.ActionLink("Opiton 1", "MyAction", new { parameter = "parm1" },
new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace,
LoadingElementId = "myDiv" })</option>
<option>@Ajax.ActionLink("Opiton 2", "MyAction", new { parameter = "parm1" },
new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace,
LoadingElementId = "myDiv" })</option>
</select>
<div id="myDiv"></div>
动作方法
public ActionResult MyAction(string parameter)
{
ViewModel myViewModel = new ViewModel();
myViewModel.Parm = parameter;
if (Request.IsAjaxRequest())
{
return PartialView("_MyPartial", myViewModel);
}
else
{
return View(myViewModel);
}
}
当我将Ajax.ActionLink
选择列表放在外部时,它可以正常工作并直接进入 MyAction。当我在选择列表中的选项内嵌入链接时,onlclick 事件无法触发。
如何让 onclick 事件在内部触发<option></option>
?