2017-04-02 60 views
1

按下「提交」按鈕後,我需要顯示成功消息。我想這一行做到這一點:嘗試創建「成功」消息時,無法從'.Controllers.AccountController'轉換爲'System.Web.UI.Page'

ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "Success", false); 

的錯誤是:

錯誤CS1503參數1:不能從 'WebApplication2.Controllers.AccountController' 轉換爲 「的System.Web 'UI.Page'

我試過尋找類似的話題,將'this'改爲'Page'等等 - 沒有運氣。任何幫助,將不勝感激。

+0

你的提交按鈕在做什麼?提交給哪個控制器操作?你能發佈你的代碼嗎? – TejSoft

+0

似乎您使用的MVC控制器可能會重定向到傳統的ASPX頁面,您能否顯示視圖頁標記? –

+0

@TejSoft您好,謝謝,我已將代碼放入帖子中,您可以請看一下嗎? – odinas1212

回答

0

問題是使用

TempData["AlertMessage"] = "Registration was successful"; 
in controller 

@{ 
    var message = TempData["AlertMessage"] ?? string.Empty; 
} 


<script type="text/javascript"> 
    var message = '@message'; 
    if(message) 
     alert(message); 
</script> 

在視圖中解決。

相關問題