【发布时间】:2010-12-23 01:42:03
【问题描述】:
我在使用 MVC 3 时遇到了一些麻烦,无法正确显示部分视图。
这是我的困境:
在我的主页/索引视图中,我有一个指向我的控制器/动作的操作链接,发布/创建:
<p>
@Html.ActionLink("Create Post", "Create", "Post")
</p>
<div id="PostCreation">
</div>
我的 Create View 是一个 partialView,带有标题、内容等的基本形式:
@using (Html.BeginForm())
{
<div>
<fieldset>
<legend>Post Creation</legend>
<div class="editor-label">
@Html.LabelFor(m => m.PostTitle)
</div>
<div class="editor-field">
@Html.TextAreaFor(m => m.PostTitle)
</div>
<p>
<input type="submit" value="Publish" />
</p>
</fieldset>
</div>
}
我在我的 _Layout.cshtml 文件中添加了一些 jQuery 来捕获对属性的点击:
<script type="text/javascript">
$(document).ready(function () {
$('a').live('click', function () {
$.get($(this).attr('href'), function (html) {
$('#PostCreation').html(html);
});
});
});
</script>
点击应该会更新 Home/Index 视图中的 PostCreation div。
使用 firebug,我发现当我逐步执行 jQuery 时,ParialView 确实会在 Home/Index 中正确呈现,但是一旦我完成 jQuery 函数,它就会呈现一个全新的页面,该页面只显示 Post/Create 表单。
感谢任何帮助。谢谢。
【问题讨论】:
标签: jquery asp.net-mvc-3