novian kristianto
novian kristianto

Reputation: 761

pass value from viewbag or viewdata to jquery

I created an application, in which I want to pass a value from ViewBag or ViewData to jQuery. Why is the value in jQuery always null?? This is my code:

My Controller

var data =  _RoomRateService.GetDataForEdit(
                                      Convert.ToInt32(Session["RoomTypeID"]),
                                      Breakfast);

var insertNewRate = _RoomRateService.insertNewRateFromList(
                    Convert.ToString(Session["RoomTypeID"]), 
                    Breakfast, 
                    CheckInTo, 
                    data.CurrCode, 
                    SingleRate, 
                    DoubleRate,
                    TripleRate, 
                    Commission, 
                    Allotment, 
                    CloseSelling, FreeSell);

ViewBag.test = data.RoomType.RoomTypeName;

My jQuery

if(RoomTypeName == "")
     {
        tr.find("#lblRoomType-"+$(this).attr('id')).text("@ViewBag.Test");
     }
     else
     {
        tr.find("#lblRoomType-"+$(this).attr('id')).text(RoomTypeName);
     }

Can some one tell me where's my fault?

Upvotes: 1

Views: 3535

Answers (1)

Imran
Imran

Reputation: 504

Try Using TempData

Controller

TempData["Key"]=Yourdata;

View

 tr.find("#lblRoomType-"+$(this).attr('id')).text("@(TempData["Key"])");

Upvotes: 1

Related Questions