Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:--

XML
<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:

C#
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
Updated 21-Apr-17 6:11am
v2
Comments
[no name] 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

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"  />
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900