Click here to Skip to main content
15,885,365 members

after calling controller method load xml file and create dynamic controls based on XML file in ASP.NETMVC View

ram salunke asked:

Open original thread
Hi currently I am working on one project this project in ASP.NETMVC based .
so need some assistance about bellow details


I have designed 1 View , and that view contains 3 html dropdown

these 3 dorpdown fill based one first dopdown option selection
like if i select 1st dropdown option then fill 2nd dropdown same as third dropdown.

my problem is that

when i am selecting third drop-down option then have called to XYZ controller method

Like

[HttpPost]
public ActionResult xyz()
{
XElement xml = XElement.Load(Server.MapPath("~/XmlMaster/CompanyLocation.xml"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/XmlMaster/CompanyLocation.xml"));
XmlElement root = xmlDoc.DocumentElement;
TempData["xml"] = xml;
TempData["xmlDoc"] = xmlDoc;
Session["FileName"] = "CompanyLocation.xml";
FirmographicInformation();
return View("FirmographicInformation");//"FirmographicInformation"
}
xyz method call to Index Method
public ActionResult Index()
{
if (Session["FileName"] != null && Session["FileName"].ToString().Trim() != "")
{
string filename = Session["FileName"].ToString().Trim();
XElement xml = XElement.Load(Server.MapPath("~/XmlMaster/" +filename));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/XmlMaster/" +filename));
XmlElement root = xmlDoc.DocumentElement;
TempData["xml"] = xml;
TempData["xmlDoc"] = xmlDoc;
Session["FileName"] = null;
return View();
}
}

then after disply view
here i have designed one html table with dynamically generated control based on XMl file

for eg

<% var listItems_Prefix = new List<SelectListItem>();
SelectList selectList = new SelectList(listItems_Prefix, "Value", "Text");
XElement xml = (XElement)TempData["xml"];
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc = (System.Xml.XmlDocument)TempData["xmlDoc"]; %>




<%
if (xmlDoc != null)
{
System.Xml.XmlElement root = xmlDoc.DocumentElement;
System.Xml.XmlNodeList controls = root.ChildNodes;

for (int i = 0; i < controls.Count; i++)
{

<%:Html.TextBox(controls[i].Attributes["id"].Value.ToString().Trim(), "")%>

}

now my problem is that
after return on view this code not executed and dynamic controls not adding on view page, and if i refresh page then my Index controller method will recall and display my expected result


so please help me regarding on that


Thank You...
Tags: MVC, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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