第一部分视图jquery selector.attrib(';id';)未定义
为什么第一个警报说未定义?请注意,警报在那里,文本框仅在我解除警报时出现 后续的“新建”单击警报“RowId”。解除警报后,我看到两个框。 下面是我对一个Ajax.Action链接的看法,它是InserterAfter第一部分视图jquery selector.attrib(';id';)未定义,jquery,asp.net-mvc-3,partial-views,Jquery,Asp.net Mvc 3,Partial Views,为什么第一个警报说未定义?请注意,警报在那里,文本框仅在我解除警报时出现 后续的“新建”单击警报“RowId”。解除警报后,我看到两个框。 下面是我对一个Ajax.Action链接的看法,它是InserterAfter @Ajax.ActionLink("New", "_New", new { Controller = "Test" } , new AjaxOptions() { InsertionMode = InsertionMode.InsertAfter,
@Ajax.ActionLink("New", "_New", new { Controller = "Test" }
, new AjaxOptions()
{ InsertionMode = InsertionMode.InsertAfter, UpdateTargetId = "divNew" })
<div id="divNew" />
@Ajax.ActionLink(“新的”、“新的”、“新的”{Controller=“Test”}
,新的AjaxOptions()
{InsertionMode=InsertionMode.InsertAfter,UpdateTargetId=“divNew”})
这是我的局部视图
RowId: @Html.TextBox("RowId")<br />
<script language="javascript">
$(document).ready(function ()
{
alert($('input[name="RowId"]').attr('Id'));
});
</script>
RowId:@Html.TextBox(“RowId”)
$(文档).ready(函数()
{
警报($('input[name=“RowId”]”)。attr('Id');
});
在主视图中尝试以下操作:
<!-- TODO: This script should be moved to a separate javascript file
because you should never mix markup and javascript. But for the
purpose of this demonstration I have left it in the view
-->
<script type="text/javascript">
var onSuccess = function (result) {
$('#divNew').append(result);
};
</script>
@Ajax.ActionLink(
"New",
"_New",
new { controller = "Test" },
new AjaxOptions() { OnSuccess = "onSuccess" }
)
<div id="divNew" />
话虽如此,如果我没有弄错,而且我的记忆力很好,我想我已经对你之前的一个类似问题发表了评论,但我会在这里重复一遍,以便其他人也能看到: 不要在部分视图或任何视图中放置任何javascript。Javascript属于单独的文件,不应与标记混合使用 我看到人们一次又一次地犯这个错误,我认为指出这一点很重要
注:您可能想使用
.attr('id')
而不是.attr('id')
我将按照您的建议使用jquery ajax。我计划使用.js文件作为视图的代码。
<!-- TODO: This script should be moved to a separate javascript file
because you should never mix markup and javascript. But for the
purpose of this demonstration I have left it in the view
-->
<script type="text/javascript">
$(function () {
$('#mylink').click(function (result) {
$.ajax(this.href, {
success: function (result) {
$('#divNew').append(result);
}
});
return false;
});
});
</script>
@Html.ActionLink(
"New",
"_New",
new {
controller = "Test"
},
new {
id = "mylink"
}
)
<div id="divNew" />