I developing WEB API project using .net C#
I need to get the value from controller.cs file and use that value into View(.cshtml) file.
My Controller Code:
HomeController.cs
XmlDocument doc = new XmlDocument();
doc.Load(httpWebResponse.GetResponseStream());
XmlElement TransID = (XmlElement)doc.SelectSingleNode("/CensusUploadResponse/TransactionID");
if (TransID != null)
{
string ResultID = TransID.InnerText;
}
I need to pass the ResultID to Index.cshtml(Ex:ResultID = 17)
MY View .cshtml file code:
Index.cshtml
<div runat="server" id="CensusuploadDiv" style="border:1px solid black; width:420px;">
</div>
I need to assign that ResultID value to CensusuploadDiv.
I try with following method using ViewBag. but's it's not working.
Assign ResultID to ViewBag like below
if (TransID != null)
{
string ResultID = TransID.InnerText;
ViewBag.Test2 = ResultID;
}
and i get the value in index file like below
<div runat="server" id="CensusuploadDiv" style="border:1px solid black; width:420px;">
@ViewBag.Test2
</div>
But value not bind to div.
XmlElement TransID = (XmlElement)doc.SelectSingleNode("/CensusUploadResponse/TransactionID")
is null? – DavidG