Cooldharma06
Cooldharma06

Reputation: 505

How to assign ViewData value as div id in asp.net mvc

hi friends help me to get out of this..

//controller
{
ViewData["idvalue"]="id"+1;
return View();
}
// Viewpage

<div id="?? "> id has to set as id1..

help me, how i can set div id as id1..?

thanks in advance.

regards,

Upvotes: 0

Views: 3742

Answers (2)

Satpal
Satpal

Reputation: 133403

Use

//controller
{
  ViewData["idvalue"] ="id1";
  return View();
}
// Viewpage

<div id='@ViewData["idvalue"]'>

However, I would recommend to use ViewBag instead of ViewData

Upvotes: 4

TGH
TGH

Reputation: 39248

{
ViewBag.idvalue ="id1";
return View();
}
// Viewpage

<div id='@ViewBag.idvalue'>

I recommend using ViewBag instead. It's just a nicer wrapper for ViewData

Upvotes: 1

Related Questions