viewmodel

ASP.NET MVC: having one model for all views

纵然是瞬间 提交于 2019-12-06 14:38:11
I like the way model binding in django works: you send stuff that you need in a Json-like way: 'param1': val, 'param2': val In ASP.NET MVC you can't do it primarily because C# is a static language. You can use ViewData but it's ugly and not recommended. So I had to create dozens of ViewModels for every view: IndexViewModel, AboutViewModel, etc. And today I got an idea: why not just create one Model class and have Visual Studio generate all necessary fields? It's almost like in django. return View(new Model { Param1 = "asd", Param2 = "sdf" }); Param1 & Param2 are not members of the Model class,

Using TempData dictionary prevents RedirectToAction from working

孤街醉人 提交于 2019-12-06 14:18:13
I want to add view model to TempData in order to pass it to another controller like this (referring to last 2 lines): [HttpPost("register")] public async Task<IActionResult> Register(RegisterViewModel rvm) { if (ModelState.IsValid) { var result = await _authManager.RegisterUserAsync(rvm.FullName, rvm.Email, rvm.Password); if (result.IsSuccessful) { return RedirectToAction("Login", "Home", new { message = result.Message }); } else { TempData["rvm"] = rvm; return RedirectToAction("Register", "Home"); } } TempData["rvm"] = rvm; return RedirectToAction("Register", "Home"); } The problem is that,

How do you make an 'attendance table' for a classroom display with an appropriate layout?

人盡茶涼 提交于 2019-12-06 13:39:08
问题 I have been having a tough time getting an attendance table for a classroom to be displayed in an appropriate fashion. I have an Attendance table in my database that I can get to display quite easily with the data from just one classroom, but it displays in a way that looks like how it would look if you browsed to the attendance table directly in the database. It is probably easier for me to explain by showing my work: I have the following classes: The actual classroom class, or Course:

How do i design a composite view and view model using Silverlight and MVVM?

折月煮酒 提交于 2019-12-06 13:31:24
I want to create a "Wizard" in my Silverlight MVVM application. The Wizard should contain multiple steps between which you can navigate using "next" and "previous". The problem I am facing is the relationship between views and view models. I want there to be a view and view model for the Wizard itself. My instinct tells me that there should be one view/view model pair for each step in the wizard. What is a good approach for maintaining these kinds of relationships, where one view model holds several other view models and the view actually consists of several smaller views? Are there any

Automapper: How to not repeat mapping config from complex type to base class

感情迁移 提交于 2019-12-06 12:54:16
I have a bunch of DTO classes that inherit from this CardBase : // base class public class CardBase { public int TransId {get; set; } public string UserId { get; set; } public int Shift { get; set; } } // one of the concrete classes public class SetNewCardSettings : CardBase { // specific properties ... } In my MVC project I have a bunch of view models with a AuditVm complex type that has the same properties of CardBase : public class AuditVm { public int TransId {get; set; } public string UserId { get; set; } public int Shift { get; set; } } public class CreateCardVm : CardVm { // specific

MVC3 collection model binding with EditorFor

空扰寡人 提交于 2019-12-06 09:30:55
Regarding this post and this other one . Suppose I have the following: public class Foo { public string Value1 { get; set; } public string Value2 { get; set; } } public class BarViewModel { public string Baz { get; set; } public IList<Foo> Foos { get; set; } } And I have a view that receive a BarViewModel : @model BarViewModel @Html.EditorFor(model => model.Baz) <table> @for(int i = 0 ; i < Model.Foos.Count ; i ++) { string name1 = "Foos[" + i.ToString() + "].Value1"; string name2 = "Foos[" + i.ToString() + "].Value2"; <tr> <td> <input type="text" name="@name1" value="@Model.Foos[i].Value1" />

Is it possible to pass a partial view a different model than the model used by the view it is in?

做~自己de王妃 提交于 2019-12-06 09:22:07
I tried to do it but I get an error saying that model x was expected but y was passed in. Yes. In fact you can use any class, but it has to match the @model declaration of your partial view. Partial View: @model partialViewModel <h2>@Model.partialViewModelProperty</h2> Main View: @model mainViewModel <h1>Model.mainViewModelProperty</h1> @Html.Partial("_PartialView", new partialViewModel() { partialViewModelProperty = "A title" }) No, that is the point of a strongly-typed View. It requires a certain type. A partial view would handle this the same as any other view. 来源: https://stackoverflow.com

MVVM Creating the ViewModel

廉价感情. 提交于 2019-12-06 09:06:38
Can somebody explain to me how exactly to create a ViewModel for the MVVM Pattern. I tried to understand the the tutorial here: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx , but I was unable to understand what exactly is happening in the code. Let's say we want to create a basic application about getting and adding people from and to a local database and displaying them in the View. How should the ViewModel look like and how to create the RelayCommands for it. First why do we set the variables twice: once privately and then again publicaly. EDIT: Thanks for the help so far. I have

How do I view the parent view model MVC3 C#?

倖福魔咒の 提交于 2019-12-06 08:57:45
I want to use two models in one view and have looked at parent view model. I have two models: public class Blogg { public int ID { get; set; } public string Blogg_name { get; set; } public string Message { get; set; } public string Blogg_subject { get; set; } private DateTime _Blogg_date = DateTime.Now; public DateTime Blogg_date { get { return _Blogg_date; } set { _Blogg_date = value; } } } And public class Dish { public int ID { get; set; } public string Title { get; set; } public string MainIngredient { get; set; } public string Cooking { get; set; } public string Drink { get; set; } public

How to navigate from one view to another view from viewmodel in silverlight?

坚强是说给别人听的谎言 提交于 2019-12-06 08:48:27
I have one ViewModel and two Views. How can I navigate to View2 from ViewModel. I read somewhere that we need to use PRISM, for opening multiple Views from ViewModel in Silverlight. Is there any alternative for PRISM? Ideally you do not want to use view logic in your viewmodel. Your viewmodel should not know anything about the view. It would be a better idea for your viewmodel to set a property letting the view know it's time to navigate. Here's an example: ViewModel : using System.ComponentModel; namespace ViewModels { public class MyViewModel : INotifyPropertyChanged { public event