Jquery 局部视图渲染问题
我正在尝试在单击事件时渲染局部视图。。。请求已成功发布到控制器,但在视图中未收到。。。我正在从控制器返回部分视图。。。下面是我的视图和控制器Jquery 局部视图渲染问题,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我正在尝试在单击事件时渲染局部视图。。。请求已成功发布到控制器,但在视图中未收到。。。我正在从控制器返回部分视图。。。下面是我的视图和控制器 <script type="text/javascript"> function postForm() { if ($('#searchresultsweather').is(':parent')) { alert("parent");
<script type="text/javascript">
function postForm() {
if ($('#searchresultsweather').is(':parent')) {
alert("parent");
var child = $('#searchresultsweather').children().attr("id");
alert(child);
$('#' + child).remove();
}
alert("about to post form");
var searchText = $('#weathersearch').val();
alert(searchText);
$.get('<%=Url.Action("SearchWeatherLocation?searchText='+searchText+'","Weather")%>', null,
function(data) {
alert("call back");
$("div#searchresultsweather").append(data);
});
}
</script>
<form id="feedForm">
<fieldset>
<p>
<input type="text" value="" maxlength="60" id="weathersearch" name="search" class="text"/>
<input type="submit" value="Search" class="submitbut" id="submitbutton_search" onclick="postForm();"/></p>
<div class="clear"></div>
</fieldset>
<div id="searchresultsweather"></div>
</form>
我认为您必须将“script”参数添加到$.get jquery调用中 所以你必须把它改成
$.get('<%=Url.Action("SearchWeatherLocation?searchText='+searchText+'","Weather")%>', null,
function(data) {
alert("call back");
$("div#searchresultsweather").append(data);
}, "script");
$.get(“”,null,
功能(数据){
警报(“回电”);
$(“div#searchresultsweather”)。追加(数据);
}“脚本”);
我认为您必须将“script”参数添加到$.get jquery调用中 所以你必须把它改成
$.get('<%=Url.Action("SearchWeatherLocation?searchText='+searchText+'","Weather")%>', null,
function(data) {
alert("call back");
$("div#searchresultsweather").append(data);
}, "script");
$.get(“”,null,
功能(数据){
警报(“回电”);
$(“div#searchresultsweather”)。追加(数据);
}“脚本”);
如果您的操作返回部分视图,则可以执行以下操作 标记/脚本
<script type="text/javascript">
function getpartial() {
var url = "<%: Url.Action("MyAction") %>";
$.ajax({
url: url,
success: function (data) {
$('#result').html(data);
}
});
return false; // stops the form submitting (if in a form)
}
</script>
<input type="button" onclick="getpartial();" title="Get partial" />
<div id="result"></div>
希望这有帮助。如果操作返回部分视图,则可以执行以下操作
<input type="submit"/>
标记/脚本
<script type="text/javascript">
function getpartial() {
var url = "<%: Url.Action("MyAction") %>";
$.ajax({
url: url,
success: function (data) {
$('#result').html(data);
}
});
return false; // stops the form submitting (if in a form)
}
</script>
<input type="button" onclick="getpartial();" title="Get partial" />
<div id="result"></div>
希望这有帮助。
<input type="submit"/>
按钮类型导致页面发回
将其更改为
按钮类型导致页面发回
将其更改为控件呈现后按钮出现问题。按钮type=“submit”导致页面发回。。。只是把它改成了“按钮”。。。Tnx punit提示回复:)问题在于控件呈现后按钮出现问题。按钮type=“submit”导致页面发回。。。只是把它改成了“按钮”。。。Tnx punit,请立即回复:)