asp.net-mvc-viewmodel

Access partial view's model in parent view

拜拜、爱过 提交于 2021-02-08 06:46:35
问题 I'm trying to access view model of a partial view in it's parent view (Home page) but, unable to do so! My scenerio: I have a partial view with it's own controller and view model. there are 3 lists being populated from DB in partial view's model: Countries, cities, and categories. I want to show categories on both partial view and it's parent with different pattern. Note: As the partial view is being used on other pages (views) also so, I can't put Categories in Home view model instead of

MVC 5 ViewBag security

六月ゝ 毕业季﹏ 提交于 2021-01-27 14:29:05
问题 I am coding an MVC internet application, and I have a question in regards to using the ViewBag. In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model. My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag? Thanks in advance. 回答1: Use your view model. When the ViewBag was implemented (MVC 3) dynamic typing was

Show multiple models in a single view using ViewModel in Razor MVC3 (with only Details in view)

久未见 提交于 2020-02-15 08:10:03
问题 My task is to show multiple models into a single view.I've created a ViewModel for my requirement but I'm not meeting my requirement. please have a look into the below code and rectify me where m i going wrong ??? public partial class StudentsDetail { public int StudentID { get; set; } public int ParentID { get; set; } public string StudentName { get; set; } public string Gender { get; set; } public string FatherName { get; set; } public string MotherName { get; set; } public Nullable<System

asp mvc list product details in view using View Model

孤街浪徒 提交于 2020-01-03 18:57:10
问题 I am trying to list single product details in a view. The product specification changes dynamically because specifications are added row-wise in table, which means we can add huge number of specifications for each product (as done in ecommerce sites). Right now I am able to meet the requirement using ViewBag , but I am deciding to use ViewModel as a better practice. Model class: // Product: public partial class ProductTable { public ProductTable() { this.SpecificationsTable = new HashSet

What is the best practice of passing data from a controller to a view layout?

一曲冷凌霜 提交于 2020-01-02 09:56:30
问题 I currently have a MVC site that needs to have dynamic content on the header of every page. I currently get the required data as normal in the controller and place it in a View Model. In the view, I take the data and stick the template parts in to the Viewbag and finally, on the main layout page, I take the Viewbag data and pass it to the partial which controls the header. I've read that I shouldn't use Viewbag where possible, and the amount of times I pass the data round just doesn't feel

ViewData and ViewModel in MVC ASP.NET

十年热恋 提交于 2020-01-01 08:43:09
问题 I'm new to .Net development, and now are following NerdDinner tutorial. Just wondering if any of you would be able to tell me What is the differences between ViewData and ViewModel (all I know is they are used to pass some form of data from controller to view) and perhaps tell me on what situation should I use ViewData instead of ViewModel and vice versa Thanks in advance! Sally 回答1: ViewData: In short, use ViewData as support data, such as a datasource to a SelectList. ViewModel: ASP.NET MVC

ViewData and ViewModel in MVC ASP.NET

余生颓废 提交于 2020-01-01 08:42:11
问题 I'm new to .Net development, and now are following NerdDinner tutorial. Just wondering if any of you would be able to tell me What is the differences between ViewData and ViewModel (all I know is they are used to pass some form of data from controller to view) and perhaps tell me on what situation should I use ViewData instead of ViewModel and vice versa Thanks in advance! Sally 回答1: ViewData: In short, use ViewData as support data, such as a datasource to a SelectList. ViewModel: ASP.NET MVC

Inserting multiple entities into many-to-many linking table

时光总嘲笑我的痴心妄想 提交于 2019-12-29 10:00:12
问题 My web application has a many-to-many link between the Station and Timetable entities, and the entity that links them is called StationTimetable , which also holds data about the linkage between the two entities. When I create a new Timetable , I want to create new (and multiple) StationTimetable entries in the database to correspond to this new Timetable . So far I've managed to get the application to save just one StationTimetable entry when the user creates a new timetable. I sort of

ViewModels with asp.net mvc 4 and EntityFramework whats the Point

孤街浪徒 提交于 2019-12-29 07:51:52
问题 I'm debating with myself whats the point in creating ViewModel classes in a project which uses Entity Framework? I currently have a project which uses EntityFramework. My solution is structured basically like this: UI project (contains controllers and Views) Model project (contains EntityFramework model) Services project (contains service classes which talk to Model Project to serve up the entities out of the model project to the UI project) My controllers pass the entities that Entity