I have a Class in my MVC app which I am calling in my contoller and getting values fill in my view
public class Mainclass
{
public List<main> mainset = new List<main>();
public void Crudmain(string path) //Capital "C" => Create, "R" => Read, "U" => update
{
XDocument x = new XDocument(new XElement("mainset"));
foreach (main main in mainset)
{
x.Root.Add(mainxml(main)); //mainxml creates xelements for main
};
x.Save(path + "/" + 0 + ".xml");
}
public class main
{
public personalinfo info { get; set; }
public addressinfo currentaddr { get; set; }
public addressinfo otheraddr { get; set; }
public telephone currenttel { get; set; }
public telephone othertel { get; set; }
}
In my controller I call Crudmain() in the action.
private main cb = new main();
[HttpPost]
public ActionResult Create(string button, main x)
// getting path via some long code
if (ModelState.IsValid)
{
cb = x;
cb.Crudmain(path);
return View("Read", cb);
}
else
{
return View("Create", cb);
}
I am getting the XML file but the data is empty. Even the Path which is dependent on the variable of a object in Personalinfo is correct but the data is empty. I have a feeling that the Crudmain is initializing a new main class. I have just transitioned from VB to C# and do not understand the methods very well can someone please help me figure out how to set the Mainclass to the one passed by controller in my code.