Click here to Skip to main content
13,150,867 members (40,791 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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;
        }
Posted 21-Apr-17 3:13am
Updated 21-Apr-17 6:11am
Bryian Tan58.4K
v2
Comments
NotPolitcallyCorrect 21-Apr-17 9:52am
   
"please give me reply as soon as possible", a reply to what? A reply to this code that you didn't describe a problem with?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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 (data) {
                $('#txtName').val(data.Name);
                $('#txtCity').val(data.City);
                $('#txtCompany').val(data.Company);
            }
        },
        error: function (a, b, c) {
            alert("error:", a, b, c);
        }
    });
</script>
 
<input type="text" id="txtName" />
<input type="text" id="txtCity" />
<input type="text" id="txtCompany"  />
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 21 Apr 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100