2011-01-08 2 views
1

클릭 이벤트에서 부분보기를 렌더링하려하고 있습니다 ... 요청이 컨트롤러에 성공적으로 게시되었지만보기에서 수신되지 않았습니다 ... 컨트롤러에서 부분보기를 반환합니다. . 아래에있는 내보기 및 컨트롤러 ...부분보기 렌더링 문제

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

는이 내 컨트롤러 측

ViewData["weather"] = weather; 
      ViewData["searchText"] = searchText;       
      return PartialView("PartialWeather"); 

답변

0
<input type="submit"/> 

버튼 타입이 다시

<input type="button"로 변경하고 작업을 확인

1

나는 당신이 당신의 $ 갔지의 JQuery와의 통화에 "스크립트"매개 변수를 추가해야합니다 생각합니다. 당신이 작업을 통해 다음을 수행 할 수있는 부분 뷰를 반환하는 경우

그래서 당신은 ...

 

$.get('<%=Url.Action("SearchWeatherLocation?searchText='+searchText+'","Weather")%>', null, 
     function(data) { 
      alert("call back"); 
      $("div#searchresultsweather").append(data); 

     }, "script"); 
 
+0

문제가 컨트롤 버튼 유형 = "제출"렌더링 된 후 버튼을이었다 페이지가 게시 일으키는 원인이 다시 게시 할 페이지 ... 방금 "버튼"으로 변경 ... 프롬프트 응답을위한 Tnx punit :) – Rafay

0

로 변경

마크 업/

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

스크립트를해야합니다 컨트롤러 동작

public ActionResult MyAction() 
    { 
     // todo: get data 
     ViewData["searchText"] = searchText;       
     return PartialView("PartialWeather", weather); 
    } 

희망이 도움이됩니다.