asp.net-mvc-viewmodel

upload 2 different files to 2 different destinations in table and folders

不想你离开。 提交于 2019-12-25 07:16:43
问题 I have a form that I'm posting 2 different files that belongs to 2 different values in my Db table. Eg. file1=user image , file2=user company logo . So I need to attach the files url to it's db value with my viewModel , something like this:(Will never work) public ActionResult Create(LectureFormViewModel viewModel) { foreach ((string item in Request.Files).viewModel.Image1) { //Do } foreach ((string item in Request.Files).viewModel.Image2) { //Do } var lecture = new Lecture { Image1 = xxx,

upload 2 different files to 2 different destinations in table and folders

旧时模样 提交于 2019-12-25 07:16:03
问题 I have a form that I'm posting 2 different files that belongs to 2 different values in my Db table. Eg. file1=user image , file2=user company logo . So I need to attach the files url to it's db value with my viewModel , something like this:(Will never work) public ActionResult Create(LectureFormViewModel viewModel) { foreach ((string item in Request.Files).viewModel.Image1) { //Do } foreach ((string item in Request.Files).viewModel.Image2) { //Do } var lecture = new Lecture { Image1 = xxx,

ASP.NET with Knockout variable length list with combobox - how to bind?

廉价感情. 提交于 2019-12-25 01:56:14
问题 With the following ASP.NET models public class User { public string Name { get; set; } public LEmail LEmail { get; set; } } public class LEmail { public IList<CLabel> Labels; public IList<CEmail> Emails; } public class CLabels { public IList<CLabel> Labels { get; set; } } public class CLabel { public string Name { get; set; } } public abstract class CEmail { public string SelectedLabel { get; set; } public string Name { get; set; } } Filling it out with dummy data and sending to appropriate

how to bind json data to existing viewmodel - mvc5

一个人想着一个人 提交于 2019-12-24 12:44:19
问题 I have a long strongly-typed form which its inputs are bound with viewmodel as html helpers, while i have a table that's not strongly-typed, it's generated when user clicks Add button, and i collect its data as json. how to map json data to viewmodel and send as one unit to post action in controller in ajax call? view @model SIServices.ViewModels.SODViewModel @using (Html.BeginForm("Initiate", "SOD", FormMethod.Post, new { id = "initiateSOD" })) // enctype = "multipart/form-data" { @Html

c# mvc: Persisting data from View to Controller and then via single object for List<ViewModel>

点点圈 提交于 2019-12-24 01:08:59
问题 I am working with a View that returns List<ViewModel> to the Controller 's Create action method. Questions: Is it correct to return List<ViewModel> to the controller? The reason I am doing is that I have to make multiple rows entry to the DB for each user. 2. My Controller implemenation is incorrect because I am trying to add data through single User object where I have recieved List of ViewModels which is only the representation of the View for single user. So how the controller should be

Is it good to define properties of “Model” type in ViewModel, ASP.net MVC

荒凉一梦 提交于 2019-12-24 01:01:54
问题 I've read couple of posts on using ViewModel in ASP.net MVC and realized it is different from "ViewModel" in M-V-VM pattern. ViewModel are used in order to avoid having Model being accessed directly from View but is it good approach to have properties of type (defined at Model layer) in ViewModel? Which means eventually we need to include Model namespace to ViewModel. E.g. Model 1. YesNoTBDValue entity/POCO class public partial class YesNoTBDValue { public int Id { get; set; } public string

MVC ASP.NET No parameterless constructor defined for this object

雨燕双飞 提交于 2019-12-23 19:46:30
问题 When I click submit in order to create an account the following error is displayed. I can't find why it is giving the following error. Also I tried to use breakpoints and debugging but it was useless No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System

Buddy ViewModel with LINQ Join

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 05:13:06
问题 SOS! What I am trying to achieve is for the logged in person, to see the users he or she is supporting (buddying). I am now trying to fully embrace ViewModels to coagulate views. I am using simplemembership MVC4 with Mysql. I have a UserProperties(all details of my users)linked to Userprofile and Everything else works. I usually use two databases one for membership and another for all other stuff. models UserProfile/UserProPerties - extended for all other properties UserId List item UserName

Data validation for every item in a list of my ViewModel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 07:02:21
问题 To make a validation with a Regex, I usually do: // In my ViewModel [RegularExpression("MyRegex", ErrorMessageResourceName = "MyErrorMessage")] public string MyField { get; set; } And the HTML helper @Html.TextBoxFor(model => model.MyField) generates a markup that looks like this: <input type="text" class="valid" name="MyField" value="" id="MyField" data-val="true" data-val-regex-pattern="MyRegex" data-val-regex="MyErrorMessage"></input> The problem is that I want to have a dynamic number of

MVC validation lost in Knockoutjs post

二次信任 提交于 2019-12-21 20:54:56
问题 I'm using MVC4 and knockout. I have a form on a page that is strongly typed to a viewmodel. In that viewmodel I have some validation defined, for instance: [Required(ErrorMessage = "Title is required")] public string Title { get; set; } If I do a standard post to the form without the required field filled, my action sees that the model is not valid and returns to the view, and a main validation message is displayed because I have @Html.ValidationSummary in my form. The individual field is