MVC :: When Using ViewModel Pass Mutiple Entites - How To Validate Them
Jun 11, 2010
when we need to pass multiple data items using a view model from a controller to a view, for example, to pass both a collection of products{id, brand, price, name} and collection of product categories{id,type} to a view, how can i validate both of these two entities?
if there is only one entity "products in the model", the validation should be somewhat like this
[Code]....
View 2 Replies
Similar Messages:
Jul 21, 2010
Tables:
"Items_table"
item_Key
Item_Name
"CartoryTable"
CatagoryID
CatagoryName
"ItemsINCatagory_Table "
INC_Key
catagoryID
Item_Key
I am using edmx. entities models and the tables are linked correctly.
I just need the code to setup the data to be passed from the controller to the view. I also have a vierwmodel for these tables.
I been looking around the net and having trouble finding a sample code.
View 9 Replies
Sep 5, 2010
In my page there is a Login form. It looks like
[Code]....
But at the same time in this page I need to render some info from another ViewModel. Is it possible to write in action something like
return View(Model1, Model2); ?And how could I get access to these ViewModels in this case?
View 2 Replies
Mar 23, 2011
I have the following scenario;
<%
using (Html.BeginForm("actionname",
"ControllerName", new
[code]...
View 1 Replies
Mar 23, 2011
I'm trying to do a post with jQuery in an MVC application, according to this SO answer here:Can jQuery do a POST of a ViewModel to a Controller in ASP.NET MVC?The difference is I am using it to delete an item in a dynamic view (never mind the fact that I'm posting a delete directly, this is a closed site by authorization, and I will use jQuery to confirm, I just don't want the user to have to go to a new page). And I therefore need to be able to send both the id and the ViewModel (the ViewModel to save any added items before deleting any). I'm not particularly happy with the solution by and large, but at this point I just need to get it to work!So I tried to figure out how to send both the id and the ViewModel according to the SO post above, but I can't figure out how to get the ViewModel in with the named parameters. This doesn't work:
$(".delete").click(function () {
$.ajax({
type: "POST",
[code]...
View 3 Replies
Dec 21, 2010
I am creating an instance of a business layer in the constructor of my Controller and then I am passing this to my view model like this;
[Code]....
The problem is when I make a post from the view with the viewmodel, I get an error that MyViewModel doesn't have a parameterless constructor defined, and I don't want it to have. Is there anyway I can pass the _businessLayer variable from the controller to the viewmodel when it's constructed "on the fly" in a method like this;
[Code]....
Maybe by using a custom model binder?
View 15 Replies
Jan 29, 2010
Writing a custom membership / role provider and have to validate user with extra parameter to Membership.Validate. So, instead of Membership.Validate(username, password) I need Membership.Validate(username, password, client).
Is this possible with the existing MembershipProvider? I would have liked to pass a new MembershipUser to the Validate method but didn't see anything that would work for that.
View 1 Replies
Jun 10, 2010
Any one know how to export mutiple tables into one excel with different sheets in asp.net application.
View 7 Replies
Jan 25, 2010
I have multiple reports that take the same parameters. Need to create a master report with all the reports merged together. I dont want to copy paste the rdlc files into one large file.found a control by Telerik called ReportBook but it costs money!! [URL]anyone knows something similar? or am i missing something very obvious?
using visual studio 2005...i have tried to generate the rdlc file on the fly. doesnt work very well with multiple datasources. falling back on copy pasting all my reports into one big rdlc file.will subreports solve my problem? not sure how these work. i have seen drill down reports work. as a matter of fact i have a two stage drill down report that needs to appear flattened on one page.so say i have a report that lists employers and i create a subreport that lists all employees for a particular empoyer. is it then possible on one rdlc to have the list of employers and a bunch of subreports for each employer's employees?
View 3 Replies
Sep 12, 2010
I looking single ajax calendar extender for multiple text boxes and (calendar) image controls?
how can we do that? I found below good article on textboxes (not calendar images) controls.
View 1 Replies
Dec 28, 2010
How to upload mutiple images with one file up;oad like in facebook or orkut using asp.net(VB).
View 1 Replies
Feb 16, 2010
its said that 1 ViewModel has 1 View. 1 View is for me a UserControl. What if my UserControl has different areas filled with data from different entities, do I have then several Views and need to build several ViewModels? e.g: I display in a UserControl 3 entities: customer(listbox),order(datagrid),product(datagrid). Each of those "data areas" has add+remove buttons and textboxes to enter data.
Actually each of those "data areas" are put in its own GRID having so the posibility to set a individual datacontext.
1.) Should I now create 3 ViewModels CustomerVM,OrderVM and ProductVM?
2.) Are those 3 "data areas" seen as an own sort of separated View, although I have not put them in 3 UserControls.xaml files ???
3.) When this one UserControl is inside a TabControl`s tabpage where do I load the 3 entities related data? Inside the MainViewModel? I want to show/load that data only when the user clicks the tabheader.
View 1 Replies
Jan 30, 2010
I have 2 properties in my ViewModel
class ViewModel1
{
Dictonary<int, string> PossibleValues {get;set;}//key/value
int SelectedKey {get;set}
}
I want to edit this using a Html.DropDownListFor I want to get MVC to auto serialize the data into/from the ViewModel so I can the following
public ActionResult Edit(ViewModel1 model) ...
View 3 Replies
Oct 25, 2010
I'm trying out the jQuery Validation plugin jQuery Docs Here is the markup of my form:
<% using (Html.BeginForm("action", "contoller", null, FormMethod.Post, new { id = "sxform" })){%>
<div id="manifest">
Manifest Option:<br />
<%= Html.DropDownList("docid", ViewData["manifests"] as SelectList, new { @class = "required" })%>
</div>
<div id="release">
Release Version:<br />
<%= Html.TextBox("release", null, new { @class = "required" })%>
</div>
<div id="locale">
Localization:<br />
<%= Html.DropDownList("localization", ViewData["localizations"] as SelectList, new { @class = "required" })%>
</div>
<div id="label">
Label:<br />
<%= Html.TextBox("label", null, new { @class = "required" })%>
</div>
<div id="session">
Session ID (optional):<br />
<%= Html.TextBox("sessionInput", null, new { @class = "required" })%>
</div>
<div id="submit"><input type="submit" value="Build" /></div>
<% } %>
JS:
$(document).ready(function(){
$("#sxform").validate();
});
I am using MS MVC HTML Helpers to render this form. The resulting markup looks fine. IE each input and selection element contains the attribute 'class' with the value 'required'. When I submit this form the validation does noting.
View 1 Replies
Mar 3, 2011
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
View 1 Replies
Mar 2, 2010
[HttpPost]
public ActionResult Edit(int id, FormCollection fc)
{
Movie movie =
(
from m in _ctx.Movie.Include("MovieActors")
where m.MovieID == id select m
).First();
MovieActorViewModel movieActor = new MovieActorViewModel(movie);
if (TryUpdateModel(movieActor))
{
_ctx.ApplyPropertyChanges(movieActor.Movie.EntityKey.EntitySetName,
movieActor.Movie);
_ctx.SaveChanges();
}
return View(movieActor);
}
However, I am not sure how to test this, and in general would much rather have the method take a typed model like:[HttpPost] public ActionResult Edit(MovieActorViewModel movieActor) Is this possible? What changes to my MovieActorViewModel class do I need to make in order to enable this? That class looks like this:
public class MovieActorViewModel
{
public Movie Movie { get; set; }
public Actor Actor { get; set; }
public PublisherDealViewModel(Movie movie)
{
this.Movie = movie;
this.Actor =
(
from a in this.Movie.Actors
where a.ActorID == 1 select a
).First();
}
}
The view is typed (inherits ViewPage) simple:
<% using (Html.BeginForm()) {%>
Movie Title: <%= Html.TextBoxFor(model=>model.Movie.Title) %><br/>
Actor Name: <%= Html.TextBoxFor(model=>model.Actor.Name) %>
<% } %>
View 3 Replies
Jun 20, 2010
I have used IDataErrorInfo Validation for my Model.
But when I use these model classes inside a view model, the validation does not happen.
sample viewmodel below
[code]....
Now, if Category or Subcategory classes are directly used as models for view, the validation works fine. But, if CategoryViewModel is used, no validation occurs.
View 1 Replies
Jan 9, 2011
I'm trying to get my own viewmodel after submit my form and I got the following error:
"Unable to cast object of type 'System.String[]' to type 'System.String'"
This is my code:
ViewMode:
public class SoftwarePackages
{
public string[] PermissionsList { get; set; }[code].....
View 3 Replies
Jan 19, 2010
A table can be used to automatically sense Model. But when I get more than one table after the SQL query is a DataTable. When this DataTable to return View (DataTable) later. In the aspx file, can automatically perceive it as the Model, as the self-paragraphs?
[Code]....
View 4 Replies
Feb 23, 2011
This is probably basic stuff, but I can't find the clear answer anywhere..Lets say I'm doing an MVC (3) application with Entity Framework (EF4), and I have these three classes:
public class Foo
{
public int FooID
[code]...
View 1 Replies
Jan 27, 2011
I have a table called "question" which consists of various columns, including 3 columns of type: bit.
these columns are: yes, no, maybe.
The corresponding viewmodel has 3 properties of type boolean. The controller returns the views, which are based on the viewmodels.
By default MVC create checkboxes for boolean types, the thing is that the properties have to be related, only 1 should be checked at a time. That is why I want to change the checkboxes to radiobuttons.
After some search on the web I tried various things, in the end I got the create working by putting three radiobuttons, tied to the same boolean field, adjusing the values.
But how to edit a question? The view is filled with data from the database, putting 1 of the 3 booleans to true.
What should my view be like, to display 3 radiobuttons, mapped to the 3 boolean types?
techniques used:
MVC 3 RC 2 with razor
Entity Framework 4 (CTP 5)
View 6 Replies
Feb 28, 2011
I have the following viewmodel definition
public class AccessRequestViewModel
{
public Request Request { get; private set; }
public SelectList Buildings { get; private set; }
public List<Person> Persons { get; private set; }
}
So in my application there must be at least 1 person for an access request. What approach might you use to validate? I don't want this validation to happen in my controller which would be simple to do. Is the only choice a custom validation attribute?
Edit: Currently performing this validation with FluentValidation (nice library!)
RuleFor(vm => vm.Persons)
.Must((vm, person) => person.Count > 0)
.WithMessage("At least one person is required");
View 4 Replies
Jul 14, 2010
http://weblogs.asp.net/shijuvarghese/archive/2010/02/01/view-model-pattern-and-automapper-in-asp-net-mvc-applications.aspxThat's Great, but it is in #C like every other tutorial I find. Note his ContactViewModelWell here is mine:
[Code]....
How do I add validation in the same fashion as he did in his blog in VB?
View 6 Replies
Nov 5, 2010
I have a ViewModel that contains an EntityObject and when I use a HtmlHelper like this
[Code]....
View 4 Replies
Mar 6, 2011
I would like to know how to use jQuery's Validate plugin to add rules to validate controls in ASCX custom user control?
View 4 Replies