2012-04-06 25 views
3

我試圖在Umbraco 5(木星)上實現AJAX,我試圖創建Surface控制器,它與普通回發很好地工作,但它不提供使用Mvc Ajax控件,例如Ajax.BeginForm等等,現在我已經在應用程序中添加了一個新的MVC區域,我可以通過Ajax表單輕鬆地將Post Back發送到Controller的Action,但是我應該從這個Action返回什麼,因爲CurrentUmbracoPage不可訪問(因爲它不是地面控制器),我的代碼是相當簡單的,Umbraco 5通過添加新的MVC區域實現Ajax

@using (Ajax.BeginForm("HandleFollowsUs", "propertyDetails", new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "POST", LoadingElementId = "ajax-loader", UpdateTargetId = "fuError" })) 
{ 
<input type="image" style="border-width: 0px;" src="/images/btnSubmitN.jpg" id="btn_submitEmail" /></span> 

} 
AND my ACTION is 
[HttpPost] 
    public ActionResult HandleFollowsUs(FormCollection collection) { 
//Do Something 
Return View();//////This is where i am confused. 
} 

如果我返回查看,它是不是在新的區域,局部視圖將只返回頁面的位部分,:/ 任何幫助將不勝感激, 謝謝, 謝爾

回答

2

使用jQuery阿賈克斯代替,並返回一個字符串,它不會影響一把umbraco 5.樣本代碼的正常路由如下

function loadList(){ 
$.ajax({ 
    type: "POST", 
    url: "/en/propertydetails/searchListView", 
    data: "loc=" + loc + "&startDate=" + startDate + "&endDate=" + endDate + "&bedrooms=" + bedrooms + "&adults=" + adults + "&children=" + children + "&offerCode=" + offerCode, 
    error: function (xhr, status, error) { 
     //alert('error'); 
    }, 
    success: function (response) { 
     //do something with response 
     populateSearchList(response); 
    } 
}); 

}

我的行動是

[HttpPost] 
    public string searchListView(string loc, string endDate, string startDate, string bedrooms, string adults, string children, string offerCode) 
    { 
//Do Something 
} 
1

你可以,如果課程發送當前的URL作爲隱藏的窗體文件,以便HandleFollowUs可以做重定向。

但是,如果我理解正確,你只是想做一些客戶端驗證?考慮使用MVC框架中已經存在的不顯眼的驗證框架。看看這篇文章瞭解更多信息:ASP.NET MVC 3 - Ajax.BeginForm vs jQuery Form Plugin

+2

感謝您的答覆sebastiaan,我不想做一個客戶端驗證,我想用戶提交他的電子郵件,因此他可以跟隨我們的通訊, 其實我正在做這一切,因爲你的包(木星作爲Visual Studio應用程序),它工作得很好,感謝一百萬,我也通過使用jquery ajax解決了這個問題。 – Sher 2012-04-07 10:20:16

+0

不客氣。會提出簡單的jQuery,但我看到你已經修復它,做得很好! – sebastiaan 2012-04-07 13:05:33