Hi Frnds,
I am new to MVC application , in my application am using viewbag here is the code
if ('@ViewBag.DTTime' != null && '@ViewBag.DTTime' != "") {
$('#Containerdiv').val('@ViewBag.DTTime.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture)');
}
in Controller not assigning the viewbag DTTime, it is error..
this if statement always true and the statement is executed,
how to stop,
Thanks in Advance.
ViewBag not working in MVC
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Saineshwar BageriRank #115 · 19.6K reputationPosted Nov 19, 2014, 6:46 PM EST
Santhosh Subramaniam189 reputationPosted Nov 20, 2014, 12:26 AM EST
{
SomeCode here ...
if (model.isSuccess) {
ViewBag.DT= DateTime.Now.GetParmsTime();
}
else
{
ViewBag.DT= '';
}
return PartialView("_PartialView", SomeModel);
}
For your reference
Saineshwar BageriRank #115 · 19.6K reputationPosted Nov 20, 2014, 2:32 AM EST
{
if (ModelState.IsValid)
{
ViewBag.DT = DateTime.Now;
}
else
{
ViewBag.DT = "";
}
return PartialView("_PartialView", SomeModel);
}