从控制器传递一个XML解析名单在ASP.NET MVC视图 [英] Passing a XML parsed list from a controller to a view in ASP.NET MVC
问题描述
我意识到这可能是一个非常愚蠢的问题在先进的非常抱歉。我试图XML列表传递给看法,但我有麻烦一旦我的看法。
I realize this is probably a very stupid question so sorry in advanced. I am trying to pass an XML list to a view but I am having trouble once I get to the view.
我的控制器:
public ActionResult Search(int isbdn)
{
ViewData["ISBN"] = isbdn;
string pathToXml= "http://isbndb.com/api/books.xml?access_key=DWD3TC34&index1=isbn&value1=";
pathToXml += isbdn;
var doc = XDocument.Load(pathToXml);
IEnumerable<XElement> items = from m in doc.Elements()
select m;
将我的观点是什么样的?我是否需要加入一些类型的XML数据控制器?
What would my view look like? Do I need to incorporate some type of XML data controller?
感谢和抱歉:)
推荐答案
第一..你必须将数据返回到视图模式...
first.. you have to return the data to the view modal...
public ActionResult Search(int isbdn)
{
ViewData["ISBN"] = isbdn;
string pathToXml= "http://isbndb.com/api/books.xml?access_key=DWD3TC34&index1=isbn&value1=";
pathToXml += isbdn;
var doc = XDocument.Load(pathToXml);
IEnumerable<XElement> items = from m in doc.Elements()
select m;
return view(m);
}
在code你后面要继承
in your code behind you have to inherit
ViewPage < IEnumerable<XElement>>
和比你ViewData.Modal将是一个强类型的IEnumerable&LT;&的XElement GT;
。
你将能够与数据在控制器的工作。
and than your ViewData.Modal will be a strongly typed IEnumerable<XElement>
.
and you will be able to work with data as in the controller.
这篇关于从控制器传递一个XML解析名单在ASP.NET MVC视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!