MVC pattern Simple XML document parsing plus vue rendering

Source: Internet
Author: User

Front-End Code:

<script src= "~/js/jquery-3.3.1.min.js" ></script>

<script src= "~/js/vue.js" ></script>

<body>
<div>
<div id= "Vue_det" >
<ul v-for= "mess in Message" >
<li>{{mess. Code}}</li>
<li>{{mess. Enname}}</li>
<li>{{mess. Name}}</li>
<li>{{mess. Level}}</li>
</ul>
</div>
</div>
<script type= "Text/javascript" >
var vm = new Vue ({
el: ' #vue_det ',
data: {
message: []
}
})
$ (function () {
$.ajax ({
type: "POST",
URL: "/home/xml",
data: "",
Success:function (AAA) {
Console.log (AAA);
vm.message = AAA;
}
})
})
</script>
</body>

Controller code:

private static list<domain> domains;
Public static list<domain> Domains
{
Get
{
if (domains = = NULL | | domains. Count <= 0)
{
domains = new list<domain> ();
XmlDocument doc = new XmlDocument ();
Doc. Load (httpruntime.bindirectory + "/resourse/domains.xml");
foreach (XmlNode node in Doc. Documentelement.childnodes)
{
domain L = new domain ();
L.code = convert.toint64 (node. attributes["Code"]. Value);
l.name = node. attributes["Name"]. Value;
l.enname = node. attributes["Enname"]. Value;
l.level = Convert.ToInt32 (node. Attributes["Level"]. Value);
L.demo = node. The text in the innertext;//child node
domains. ADD (l);
}
}
return domains;
}
}
Public jsonresult XML ()
{
return Json (Domains);
}

Simple Ajax request that returns the contents of the JSON//xml file

MVC pattern Simple XML document parsing plus vue rendering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.