---
title: "XML Record Value in mvc"  
description: "XML Record Value in mvc"  
author: "Anonymous User"  
published: 2014-11-09  
updated: 2014-11-10  
canonical: https://www.mindstick.com/forum/2544/xml-record-value-in-mvc  
category: "asp.net mvc"  
tags: ["c#", "xml", "mvc4", "xml reader"]  
reading_time: 1 minute  

---

# XML Record Value in mvc

I have an [xml file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php):

```
<profiles>
  <profile username="user4" fullname="Full Name" />
 </profiles>
```

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to retrive the [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of the fullname, here is what I tried:

```
public List<string> GetFullName(string username)
{
    List<Profile> list = null;
    try
    {
        list = (from t in ProfileList
                where t.UserName == username
                select t).FirstOrDefault();
    }
    catch { }
    List<string> userFullName = new List<string>();
    if (list != null)
    {
        foreach (Profile t in list)
        {
            userFullName.Find(t.FullName);
        }
    }
    return userFullName;
}
```

[FirstOrDefault](https://www.mindstick.com/forum/159561/when-to-use-first-and-when-to-use-firstordefault-with-linq) gives an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing)!

## Replies

### Reply by Anonymous User

I'd rather rewrite your code like this

```
    public String GetFullName(string username)    {        var targetObject = (from t in ProfileList                    where t.UserName == username                    select t).FirstOrDefault();         if (targetObject != null) return targetObject.FullName; throw new Exception("Target
user is not found");    }
```


---

Original Source: https://www.mindstick.com/forum/2544/xml-record-value-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
