viewbag

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

纵然是瞬间 提交于 2019-12-17 18:02:54
问题 I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

左心房为你撑大大i 提交于 2019-12-17 18:02:05
问题 I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works

How to display a list using ViewBag

久未见 提交于 2019-12-17 15:36:31
问题 Hi i need to show a list of data using viewbag.but i am not able to do it. Please Help me.. I tried this thing: ICollection<Learner> list = new HobbyHomeService().FetchLearner(); ICollection<Person> personlist = new HobbyHomeService().FetchPerson(list); ViewBag.data = personlist; and inside view: <td>@ViewBag.data.First().FirstName</td> But this does not show up the value and gives error saying "Model.Person doesnot contain a defibition for First()" 回答1: In your view, you have to cast it back

Convert viewbag to javascript array

血红的双手。 提交于 2019-12-14 01:23:22
问题 I want to get the data from the ViewBag.mytags to a Javascript array, but I was not able to avhice this $(function () { var sampleTags = new Array(); var array = @Html.Raw(Json.Encode(@ViewBag.mytags)); for(var i =0; i<array.length;i++){ sampleTags[i] = array[i]; } $('#singleFieldTags').tagit({ availableTags: sampleTags, singleField: true, singleFieldNode: $('#mySingleField') }); } This is my controller ViewBag.mytags = mp3.TagSuggestion(); This is my Models public IQueryable<string>

Access variables inside JQuery dialog

天大地大妈咪最大 提交于 2019-12-13 18:23:42
问题 I have a user ID in viewBag I want to access the ViewBag inside my dialog box <script> $(function () { $("#dialog").dialog({ autoOpen: false, modal: true, width: 339, overlay: { backgroundColor: 'red', opacity: 0.5 }, show: { effect: "blind", duration: 500 }, hide: { effect: "explode", duration: 700 } }); }); function OpenDialog() { $('#dialog').dialog("open"); } </script> <div id="open" onclick="OpenDialog();">Click To Open</div> @ViewBag.UserID <div id="dialog"> <table> <tr> <td>User ID</td

Passing a model object through ViewBag

百般思念 提交于 2019-12-13 15:08:06
问题 I was wondering if it is possible to pass a model object through ViewBag. I tried the following codes but somehow in my View, it is only the path of the model which is displayed. Controller: public ActionResult Tempo() { DateTime date1 = new DateTime(1990, 1, 1); Employee emp = new Employee(3, "fara", "hass", date1, 56.6m, 0); ViewBag.EmployeeId = emp.EmployeeID; ViewBag.Fname = emp.Fname; ViewBag.Employee = emp; } View: @{ ViewBag.Title = "Tempo"; } @model LayoutProject.Models.Employee <h2

Declare ViewBag on controller

孤者浪人 提交于 2019-12-12 18:07:42
问题 I'm using ViewBag.Message with the same message several times into the methods on the controller. It is possible to declare ViewBag.Message on the top of the class, so can be used in the whole controller without repeat the code? 回答1: Assuming Razor syntax you can achieve this with. @{string pageMessage = ViewBag.Message.ToString();} then pageMessage is a local variable available to the page, for example: <h1>@pageMessage</h1> EDIT ViewBag is a dynamic object which is a member of the

Can I use ViewBag in an .aspx page?

不打扰是莪最后的温柔 提交于 2019-12-12 11:36:57
问题 I have to move my UI page from a .cshtml file to an .aspx file. Now I'm having a couple of compiling errors. First is that 'ViewBag' does not exist in the current context. Can I not use it in .aspx? If not, what is a good substitute? Second, the .cshtml page had a model declaration: @model myProject.Models.Navigation I changed it so that it would work in the .aspx page as follows: <%@ Import Namespace="myProject.Models" %> I'm still not sure that's a correct substitute, because I could not

Passing a Value from a ViewBag to a partial View

ⅰ亾dé卋堺 提交于 2019-12-12 10:19:48
问题 So my Controller's code is as follows: private CommunityModelsContext dbCommunities = new CommunityModelsContext(); // GET: /Home/ public ActionResult Index() { //retrieve the Communities ViewBag.Communities = dbCommunities.Communities.ToList(); return View(); } And my View has this all important line to start the Partial View <div id="LeftView" class="PartialView">@{Html.RenderPartial("CommunitiesPartial");}</div> and in the Partial view, I'm trying to create a DropDownList (I'm still

Change button text onclick with condition

爷,独闯天下 提交于 2019-12-11 20:18:59
问题 My aim is to have a button, with default value Block and when the user click on it, it will change the text to Unblock and also after page refresh the text of the button must remain the same, if the text is changed to unblock then after refresh it must remain unblock. What i have tried uptil now is this: View code for Button: input type="submit" value="@ViewBag.SubmitValue" id="Block" style="color: white; background-color: darkred; border-bottom-left-radius: 2px; border-bottom-right-radius: