viewbag

MVC3 RedirectToAction in a post method and ViewBag suppression

风流意气都作罢 提交于 2019-11-30 12:31:56
i'm currently working a list of data that i need to display in a view that represent a list and show for each item the corresponding action that can be executed, like edit them or delete them. For the edition there is no problem concedering that it's a particular view. My problem is when i want to delete an item, i have two choices in the post method. //Call directly the list [HttpPost] [Authorize] public ActionResult Delete(int itemId) { // logic to delete an item ViewBag.Error = ""; // The result of the execution return List(); } The thing with this solution is that the url is no longer the

Storing an Anonymous Object in ViewBag

烂漫一生 提交于 2019-11-30 08:13:14
This is probably a silly question, but I am trying to stuff an anonymous object in ViewBag like so: ViewBag.Stuff = new { Name = "Test", Email = "user@domain.com" }; and access it from a View like so: @ViewBag.Stuff.Name I understand ViewBag is dynamic and that "Stuff" is an anonymous object... but when I look with the debugger from the View line above, I can see all the properties with the proper values. Why does the model binder have such a hard time with this? Is there a good way to accomplish this without creating a model class? I want to continue using new {} SoWeLie Essentially the issue

Difference between viewbag and viewstate?

我的梦境 提交于 2019-11-30 06:49:14
Is there a functional difference between ViewState in Webforms and ViewBag in MVC? They seem to be the "same thing". And can be used in the same ways. I ask because MVC promotes the stateless Web and not stuffing data in the page causing bloat and slower performance. But it seems that you can do that in MVC as well. All they did, seemingly, is just give it a new name. ViewState in Web Forms was serializing form data into a hidden, encrypted field in the form, so data could be re-bound on the postback. ViewBag/ViewData is a dictionary where you can "stuff" data into. For example, you might add

using viewbag with jquery - asp.net mvc 3

╄→尐↘猪︶ㄣ 提交于 2019-11-30 03:57:16
I have a ViewBag.IsLocal set to true in controller. I would like to use jquery to check the ViewBag value and display an alert. Code: if(@ViewBag.IsLocal == true) { alert("yeah"); } I never get the alert. When I use Firebug to see the value of ViewBag it's True ( with capital T). Do I have to do something like == 'True'? I tried it all and none of that worked. Thank you for help. H If you view source on the rendered page, what's being inserted in place of your razor nugget? If IsLocal is a bool type, I think you'll see this: @if(True == true) { alert("yeah"); } The reason for that is because

How do I render HTML from the Viewbag using MVC3 Razor

偶尔善良 提交于 2019-11-29 23:27:31
I am trying to pass a form element into an MVC3 view by using the Viewbag and simply write the HTML to the page ... In controller: ViewBag.myData = "<input type=""hidden"" name=""example"" value=""examplevalue"">"; In view (I know I could use a helper for the form): <form action="http://exampleurl/examplepage" method="post" id="example-form"> @ViewBag.myData <input type="hidden" name="anotherexample" value="anotherexamplevalue" /> </form> This renders the myData as text in the HTML i.e.: <type="hidden" name="example" value="examplevalue"> So my question is how do I get Razor to do the

MVC3 RedirectToAction in a post method and ViewBag suppression

做~自己de王妃 提交于 2019-11-29 18:24:24
问题 i'm currently working a list of data that i need to display in a view that represent a list and show for each item the corresponding action that can be executed, like edit them or delete them. For the edition there is no problem concedering that it's a particular view. My problem is when i want to delete an item, i have two choices in the post method. //Call directly the list [HttpPost] [Authorize] public ActionResult Delete(int itemId) { // logic to delete an item ViewBag.Error = ""; // The

c# mvc model vs viewbag

旧城冷巷雨未停 提交于 2019-11-29 13:19:46
Suppose you have a list of People A and a list of People B in a page. And these two are seperate classes in L2S, representing two different tables. Therefore, you cannot pass a single model as follows: ... @model PeopleA ... @foreach(var peopleA in Model.People) ... @foreach(var peopleB in //what?) Accordingly, I guess, I have three options to follow. The first one is to devide the page into partial views so that I can pass a model through RenderAction helper. Since I will use these partial views only once this option does not seem attracting to me. The second option would be to use ViewBags

Lifetime of ViewBag elements in ASP.net MVC3

蹲街弑〆低调 提交于 2019-11-29 09:12:19
When will the values of the ViewBag be flushed or cleared ? When you leave the view on subsequent request. ViewBag is created in the controller and it will live until the rendering of the view. In addition to this it is something that I would not recommend you using and replace it with view models. 来源: https://stackoverflow.com/questions/6858723/lifetime-of-viewbag-elements-in-asp-net-mvc3

using viewbag with jquery - asp.net mvc 3

扶醉桌前 提交于 2019-11-29 01:36:30
问题 I have a ViewBag.IsLocal set to true in controller. I would like to use jquery to check the ViewBag value and display an alert. Code: if(@ViewBag.IsLocal == true) { alert("yeah"); } I never get the alert. When I use Firebug to see the value of ViewBag it's True ( with capital T). Do I have to do something like == 'True'? I tried it all and none of that worked. Thank you for help. H 回答1: If you view source on the rendered page, what's being inserted in place of your razor nugget? If IsLocal is

How do I access ViewBag from JS

泪湿孤枕 提交于 2019-11-28 22:39:09
My attempted methods. Looking at the JS via browser, the @ViewBag.CC is just blank... (missing) var c = "#" + "@ViewBag.CC"; var d = $("#" + "@ViewBag.CC").value; var e = $("#" + "@ViewBag.CC").val(); var c = "@ViewBag.CC"; var d = $("@ViewBag.CC").value; var e = $("@ViewBag.CC").val(); if you are using razor engine template then do the following in your view write : <script> var myJsVariable = '@ViewBag.MyVariable' </script> UPDATE: A more appropriate approach is to define a set of configuration on the master layout for example, base url, facebook API Key, Amazon S3 base URL, etc ...``` <head