viewmodel

ASP.Net MVC and state - how to keep state between requests

杀马特。学长 韩版系。学妹 提交于 2019-12-17 15:26:53
问题 As a fairly experienced ASP.Net developer just recently starting using MVC, I find myself struggling a bit to change my mindset from a traditional "server control and event handler" way of doing things, into the more dynamic MVC way of things. I think I am slowly getting there, but sometimes the MVC "magic" throws me off. My current scenario is to create a web page that allows the user to browse a local file, upload it to the server and repeat this until he has a list of files to work with.

Why do I get null instead of empty string when receiving POST request in from Razor View?

╄→гoц情女王★ 提交于 2019-12-17 15:25:11
问题 I used to receive empty string when there was no value: [HttpPost] public ActionResult Add(string text) { // text is "" when there's no value provided by user } But now I'm passing a model [HttpPost] public ActionResult Add(SomeModel Model) { // model.Text is null when there's no value provided by user } So I have to use the ?? "" operator. Why is this happening? 回答1: You can use the DisplayFormat attribute on the property of your model class: [DisplayFormat(ConvertEmptyStringToNull = false)]

ASP.NET MVC: using EF entities as viewmodels? [duplicate]

跟風遠走 提交于 2019-12-17 10:49:19
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: ASP.NET MVC - Linq to Entities model as the ViewModel - is this good practice? Is is OK to use EF entities classes as view models in ASP.NET MVC? What if viewmodel is 90% the same of EF entity class? Let's say I have a Survey class in Entity Framework model. It 90% matches data required for view to edit it. The only difference from what view model should have - is one or several properties to be used in it (that

MVVM ViewModel vs. MVC ViewModel

笑着哭i 提交于 2019-12-17 08:47:49
问题 ViewModel is a term that is used in both MVVM (Model-View-ViewModel) and the recommended implementation for ASP.NET MVC. Researching "ViewModel" can be confusing given that each pattern uses the same term. What are the main differences between the MVC ViewModel and MVVM ViewModel? For example, I believe the MVVM ViewModel is more rich, given the lack of a Controller. Is this true? 回答1: A rather challenging question to answer succinctly, but I'll attempt it. (Bear in mind that the answers to

MVVMCross changing ViewModel within a MvxBindableListView

眉间皱痕 提交于 2019-12-17 06:54:46
问题 Little problem with my Android application and I don't know how to solve it with MVVM Cross. Here is my Model public class Article { string Label{ get; set; } string Remark { get; set; } } My ViewModel public class ArticleViewModel: MvxViewModel { public List<Article> Articles; .... } My layout.axml ... <LinearLayout android:layout_width="0dip" android:layout_weight="6" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/layoutArticleList"> <EditText android

MVVMCross changing ViewModel within a MvxBindableListView

丶灬走出姿态 提交于 2019-12-17 06:53:17
问题 Little problem with my Android application and I don't know how to solve it with MVVM Cross. Here is my Model public class Article { string Label{ get; set; } string Remark { get; set; } } My ViewModel public class ArticleViewModel: MvxViewModel { public List<Article> Articles; .... } My layout.axml ... <LinearLayout android:layout_width="0dip" android:layout_weight="6" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/layoutArticleList"> <EditText android

Having trouble binding ViewModel to ComboBox

妖精的绣舞 提交于 2019-12-14 04:09:35
问题 I have a viewmodel setup as the following public class cDriveListVM { public string Drive { get; set; } public cDriveListVM(string name) { Drive = name; } } I declare the observablecollection in the window and set its datacontext to this observable collection. public ObservableCollection<cDriveListVM> DriveList { get; set; } private void dl() { DriveList = new ObservableCollection<cDriveListVM>(); DriveList.Add(new cDriveListVM("drive 1")); DriveList.Add(new cDriveListVM("drive 2")); this

How do I transfer ViewModel data between POST requests in ASP.NET MVC?

青春壹個敷衍的年華 提交于 2019-12-14 03:53:33
问题 I have a ViewModel like so: public class ProductEditModel { public string Name { get; set; } public int CategoryId { get; set; } public SelectList Categories { get; set; } public ProductEditModel() { var categories = Database.GetCategories(); // made-up method Categories = new SelectList(categories, "Key", "Value"); } } Then I have two controller methods that uses this model: public ActionResult Create() { var model = new ProductEditModel(); return View(model); } [HttpPost] public

A viewmodel has a behavior/methods compared to a DTO but

这一生的挚爱 提交于 2019-12-14 03:13:31
问题 People on SO often say:"A ViewModel holds methods that can be executed by the view, properties to indicate how toggle view elements, etc. ..." When my ViewModel is sent as a WebApi response to the client serialized to JSON , how can this ViewModel execute a method on the client? This is not clear at all to me. 回答1: You can understand viewmodel in at least two ways instead of passing your business objects to the view (for example MVC Razor view) you pass stripped down objects that contain

View, ViewModel and DataContext

那年仲夏 提交于 2019-12-13 21:41:04
问题 In order to solve a navigation issue in my application I have used an Event Aggregator which has solved the problem but has created an other one. To navigate between different UserControls I used the Rachel's code you can find here which was working fine until I made some changes. On the side of my screen I have a Main Menu ( HomeViewModel() ), by clicking on the items I switch between UserControls and in each of these UserControls there is a another menu bar where I can switch between other