如何使用ASP.NET MVC从XML获取数据到文本框? [英] How to fetch the data from XML to textboxes using ASP.NET MVC?

查看:205
本文介绍了如何使用ASP.NET MVC从XML获取数据到文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨成员,



我有疑问。



如何获取文本框中的数据(字段)通过使用asp.net MVC或jQuery单击上传的按钮控件已经存储在XML文件中的数据?





例如设计: -



有三个文本框(字段)



名称:这里文本框(< input type =text/>它在html控件中)



公司:textbox

城市:textbox



这些文本框下的按钮



提交上传文件



当我点击uploadfile然后XML文件有数据然后我想在文本框字段中获取数据。



XML文件示例: -



Hi members,

I have question.

How to fetch the data in text boxes (fields) which is already stored data in XML file by clicking uploaded button control in the form by using asp.net MVC or jQuery?


For example design:-

there are three textboxes(fields)

Name:here textbox(<input type="text" /> it is in html control)

Company: textbox
City: textbox

here buttons under these textboxes

submit uploadfile

When I click on the uploadfile then what the XML file has data then I would like to fetch the data in text box fields.

example of XML file:--

<FAddress id="1">
<Name> Fedex</Name>
<Company>Processweaver</Company>
<City> Hyderabad</City>
</FAddress>





所以请请尽快给我答复



谢谢



我尝试过:





so please give me reply as soon as possible

Thank you

What I have tried:

public FromAddress GetLoad(string strpath)

        {
            FromAddress ad = new FromAddress();
            XmlDocument objdoc = new XmlDocument();
            //str = @"C:\Users\E461\Documents\Visual Studio 2015\Projects\XCarrierMVC\XCarrierDAL\XCarrier.xml";
            objdoc.Load(strpath);
            XmlNodeList xlist = objdoc.GetElementsByTagName("FAddress");
            foreach (XmlNode node in xlist)
            {

                ad.Name = node.ChildNodes[0].InnerText;
                ad.Company = node.ChildNodes[1].InnerText;
                ad.City = node.ChildNodes[2].InnerText;
            }
            return ad;
        }

推荐答案

试试



控制器

try

Controller
public ActionResult GetData() {
            var data = GetLoad("path");
               return Json(data);
        }



查看




View

<script src="~/Scripts/jquery-1.8.2.js"></script>
<script>


.ajax({
type:POST,
url:'@ Url.Action(GetData, YourControllerName)',
contentType:application / json; charset = utf-8,
dataType:json,
success:function(data){
if(
if(数据){
.ajax({ type: "POST", url: '@Url.Action("GetData", "YourControllerName")', contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (data) {


('#txtName')。val(data.Name);
('#txtName').val(data.Name);


这篇关于如何使用ASP.NET MVC从XML获取数据到文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆