viewdata

keep viewdata on RedirectToAction

孤人 提交于 2020-05-24 11:48:32
问题 [AcceptVerbs(HttpVerbs.Post)] public ActionResult CreateUser([Bind(Exclude = "Id")] User user) { ... db.SubmitChanges(); ViewData["info"] = "The account has been created."; return RedirectToAction("Index", "Admin"); } This doesnt keep the "info" text in the viewdata after the redirectToAction. How would I get around this issue in the most elegant way? My current idea is to put the stuff from the Index controlleraction in a [NonAction] and call that method from both the Index action and in the

Is it good practice to pass TempData and/or ViewData to services?

China☆狼群 提交于 2020-02-04 15:56:50
问题 In trying to reduce the size of my MVC controllers, I am refactoring a lot of logic out into services (though this same issue would apply if it was being factored into models). I'm often finding that I was directly setting ViewData and/or TempData with information I wanted to be displayed to the user, like: var repoUser = new UserRepository(); var foundUser = repoUser.GetUser(userId); if (foundUser == null) { ViewData["ErrorMessage"] = "Could not find user with ID {0}.".FormatWith(userId);

How should we pass a data to a view in a big ASP.NET MVC web site

霸气de小男生 提交于 2020-01-24 17:12:44
问题 First of all, I have been a php programmer for a long time and I am a mvc programmer newly. I did a few minor web sites that each have one or two controller at most. But I've started a website that will be very major web site. There will be a lot of data to pass to views. Now, normally I try to use model approach every time instead of ViewBag or ViewData approach. If the view demands more data, then I change the model class and then recompile the project. Especially, if the topic is an index

Asp MVC 3: Modifiy Values Sent to View

安稳与你 提交于 2020-01-16 16:17:01
问题 as far as I understand a ModelBinder can generate class instances out of routedata/formdata . What I'm looking for is a way to manipulate the data handed over to the view before it is consumed by the view. What are the possiblities? Do I miss something obvious? Thanks in advance! EDIT I don't want to send clear IDs to the client but encrypt them (at least in edit cases). As it happens very often I want this step as much as possible automated. I look for something like a ModelBinder or a

Asp MVC 3: Modifiy Values Sent to View

你。 提交于 2020-01-16 16:16:26
问题 as far as I understand a ModelBinder can generate class instances out of routedata/formdata . What I'm looking for is a way to manipulate the data handed over to the view before it is consumed by the view. What are the possiblities? Do I miss something obvious? Thanks in advance! EDIT I don't want to send clear IDs to the client but encrypt them (at least in edit cases). As it happens very often I want this step as much as possible automated. I look for something like a ModelBinder or a

ASP.NET MVC 2 - ViewData empty after POST

爷,独闯天下 提交于 2020-01-04 01:25:11
问题 I don't really know where to look for an error... the situation: I have an ASPX view which contains a form and a few input's, and when I click the submit button everything is POST'ed to one of my ASP.NET MVC actions. When I set a breakpoint there, it is hit correctly. When I use FireBug to see what is sent to the action, I correctly see data1=abc&data2=something&data3=1234. However, nothing is arriving in my action method. ViewData is empty, there is no ViewData["data1"] or anything else that

ASP.NET MVC ViewData and view model best practices

半城伤御伤魂 提交于 2020-01-02 05:58:10
问题 The initial situation is that I map my domain model into a presentation model. I have to display an update/create formular with textboxes and a dropdownlist. Should the viewmodel contain a list for the dropdownlist or should I pass the data for the dropdownlist by using ViewData? When should I use ViewData and when should I not use it? Shall input fields like dropdownlists have a seperate view model? 回答1: I tend to try and use ViewData as little as possible since you always need to cast

mvc no codebehind strongly typed viewdata headers not working

旧巷老猫 提交于 2020-01-02 04:07:28
问题 I add that to my header <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> and am able to access ViewData and all its internals as well as all the mvc objects like url and html. As soon as I add " System.Web.Mvc.ViewPage<app.Models.tTable> " I have no access to any mvc classes and helper methods. I am confused on why this is. I have done an upgrade from mvc preview 5 to rc1 recently but my transition to rc1 was flawless without any errors

C# Centralizing repeating VIewData in MVC

Deadly 提交于 2020-01-01 10:06:53
问题 When a user log in into my application i want to show his name throughout the whole application. I am using the asp.net MVC framework. But what i don't want is that is have to put in every controller something like: ViewData["User"] = Session["User"]; This because you may not repeat yourself. (I believe this is the DRY [Don't Repeat Yourself] principle of OO programming.) The ViewData["User"] is on my masterpage. So my question is, what is a neat way to handle my ViewData["User"] on one place

Should I always use a view model or is it ok to use ViewData?

丶灬走出姿态 提交于 2019-12-31 04:31:07
问题 when do you think is it better to use ViewData over a view model? I have the same exact partial view in a couple of main views. I'd like to control how a partial view is rendered but I'd also prefer the partial view to accept only a view model which is a collection of records, just a pure IEnumerable<> object. I'd rather avoid to send the full view model object from a main view because it also contains a lot of different properties, objects, that control paging, sorting, filtering etc.