WebIn ASP.NET Core MVC, we can use both ViewData and ViewBag to pass the data from a Controller action method to a View. The ViewData is a weakly typed dictionary object … WebOct 7, 2024 · You can use ViewBag as community memeber said,This is of type dynamic .You can put any data into viewbag and use it in you view as below Controller Action ViewBag.Data="Value"; View @ViewBag.Data Note: View bag values will be available only in the view. The subsequest request the data will be lost.
What is ViewBag: How It Works & Code Examples - Stackify
WebYou cannot use an anonymous type to pass data from action method to view, via ViewBag. 您不能使用匿名类型通过ViewBag将数据从操作方法传递到视图。 Create a view model class to represent this data you want to pass. 创建一个视图模型类来表示您要传递的数据。 Webpassing selectlists by viewbag This solves our problem, but we do not like using ViewBag: public ActionResult Create () { ViewBag.SomeModels = new SelectList (context.SomeModel, "id", "modelDescription"); return View (); } Our solution We added a context to a viewmodel to do the same, but this is MVC anti-pattern: cholesteatoma pain
How to pass parameter to MVC controller - qnacoding.com
WebAug 11, 2024 · In general, ViewBag is a way to pass data from the controller to the view. It is a type object and is a dynamic property under the controller base class. Compared to … WebMar 14, 2011 · 7 solutions Top Rated Most Recent Solution 4 if you bind model to view you will get the selected value directly in controller (without binding the model also we can achieve the selected value from ajax hit) 1.tell me few things have you bind any model to the view in which your dropdown exist.? 2. did you write post action method in controller? WebOct 7, 2024 · I think that you should use the ViewBag dynamic property: public ActionResult DoWork { ViewBag.Flag = false; if (// some conditions) { ViewBag.Flag = true; } return PartialView (); } in the View: @ if (@ViewBag.Flag) { You can do this } else { You can do that } Sunday, December 11, 2011 9:06 AM 0 Sign in to vote gray striped bug