2013-08-07 69 views
0

初始:行動返回PartialViewResult,必須返回字符串(HTML代碼)

public ActionViewResult Action_ASDA(Model model) 
{ 
... 
... 
return PartialView("My_Model_View",model); 
} 

確定..現在我需要這個函數返回的HTML代碼(同樣的功能,但我需要返回作爲字符串的HTML )

public string Action_ASDA(Model model) 
{ 
... 
... 
// HTML RESPONSE 
Response.Clear(); 
Action_ASDA(model).ExecuteResult(ControllerContext); 
Action_ASDA(model).ExecuteResult(ControllerContext); 
return Response.ToString().Replace("System.Web.HttpResponseWrapper", string.Empty); 

} 

其中顯示「...」是模型生成和補充的代碼。

回答

0

如果你想返回HTML字符串,你可以使用:

string html = "<div>Hello, this is div</div>"; 
return Content(html, "text/xml"); 
+0

我誰是從模型動態生成的視圖。如果你會告訴我如何爲你的變量「html」設置值,那就沒問題。 – Alynuzzu

+0

不知道我明白你的意思。如果您使用的部分景色,像你這樣在第一次爲什麼不返回'PartialView'? – Artless

+0

因爲我需要另一種解決方案來刷新我的局部視圖自動。 – Alynuzzu