So I'm looking at moving from MVC 1.0 to MVC 2.0 RTM. One of the conventions I'd like to start following is using the strongly-typed HTML helpers for generating controls like text boxes.
However, it looks like it won't be an easy jump. I tried migrating my first form, replacing lines like this:
<%= Html.TextBox("FirstName", Model.Dat...
I have a textbox that I am defining as
<%= Html.TextBox("Username", Model.Form.Username,
new { @class = "textbox", @disabled = "disabled" })%>
In my action
[AcceptVerbs(HttpVerbs.Post)]
[ValidateAntiForgeryToken]
public ActionResult EditLogin(LoginForm post) {
...
return View(model);
}
pos...
I have a ViewModel class to encapsulate "Personal" and "Business" models. My problem is that both models have a property called "Email" and the model binding is not able to make a distinction between the two.
I read that [Bind(Prefix = ... is used to resolved this issue, but I have not been able to see a concise example on how to achie...
Okay, so I'm fairly new to model binding in MVC, really, and my question is this:
If I have a model with an IEnumerable property, how do I use the HtmlHelper with that so I can submit to an Action that takes that model type.
Model Example:
public class FooModel {
public IEnumerable<SubFoo> SubFoos { get; set; }
}
public class Sub...
Hi
I have a complex entity User:
public class User : BaseEntity
{
public virtual Taxi Taxi { get; set; } --> That is why i call it "complex"
public virtual string Login { get; set; }
public virtual string Password { get; set; }
}
where Taxi is a parent of User (Taxi has-many Users):
...
Hello!
My question is fairly simple: I have a custom ActionFilterAttribute which looks like this (simplified for readability):
public class DynamicModuleActionAttribute : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
filterContext.ActionParameters["module"] = new MyObj...
I want to bind POSTed form values to parameters in my WCF operation in the same way that ASP.Net MVC allows me to do.
So, for example if my form has "customer.Name" and "customer.Age" parameters, I want to make a standard HTML POST to a named endpoint/operation that takes a customer parameter and have it instantiated and populated like ...
I tried to use Controller.TryUpdateModel() of ASP.NET MVC. What does it do in detail. In my example it fails (i.e. returns false). So how can I find out, what is the reason for the failure?
...
I have a need to add custom HTML attributes, specifically classes or styles to option tags in the selects generated by Html.DropDownFor().
I've been playing with it, and for the life of me I can't figure out what I need to do to get what I need working.
Assuming I have a list of colors that I'm generating the dropdown for, where the op...
Once again I'm confronted with a "This shouldn't be this ?*!# hard" situation.
Problem: I want to use a form in MVC for creation of an object. One of the elements of the object is a set of limited choices - a perfect candidate for a drop down list.
But if I use a SelectList in my model, and a drop down list in my View, and then try to ...
This is a really strange behavior, and I've set up some demo code to try to figure out what's going on.
Basically have a a two actions and a single view. The first action sends an empty model to the view, the section action recieves the model, alters its contents and sends it back to the same view.
The wierdness is, in the view, the Mo...
Does ASP.NET MVC offer any simple way to get model binding to work when you have model classes that inherit from others?
In my scenario I have a View that is strongly typed to List<Person>.
I have a couple of classes that inherit from Person, namely PersonTypeOne and PersonTypeTwo.
I have three strongly typed partial views with names ...
This one seems painfully obvious to me, but for some reason I can't get it working the way I want it to. Perhaps it isn't possible the way I am doing it, but that seems unlikely. This question may be somewhat related: http://stackoverflow.com/questions/1274855/asp-net-mvc-model-binding-related-entities-on-same-page.
I have an EditorTemp...
I'm using MVC 2 and MVC Futures 2.0.50217.0.
I started with a view which repeatedly calls RenderAction(...) to include some external content implemented by another controller within my application. This is from the containing view:
<% foreach (var subModel in Model.SubModels) { %>
<h3><%: subModel.Title %></h3>
<% Html.RenderAc...
I'm trying to highlight certain form fields (let's call them important fields) when they're empty. In essence, they should behave a bit like required fields, but they should be highlighted if they are empty when the user first GETs the form, before POST & model validation has occurred. The user can also ignore the warnings and submit the...
I have created an OrderFormViewModel which looks something like
public class OrderFormViewModel
{
public IOrderDetails { get; set; }
public IDeliveryDetails { get; set; }
public IPaymentDetails { get; set; }
// ... etc
public SelectList DropDownOptions { get; set; }
// ... etc
}
This goes to my Create view, ...
I'm following Phil's great tutorial on model binding to a list.
I use input names like this:
book[5804].title
book[5804].author
book[1234].title
book[1234].author
This works well and the data gets back to the model just fine, populating a list of books.
What I'm looking for is a way to get access in the model to the index that was u...
I have entries for an enumeration stored inside a database table with only the following fields: ID and Name. I want to show the values stored inside this table inside a DropDownList on a form. The user then chooses a value and submits the form.
I found a way to easily create a DropDownList from an enumeration (although it would probabl...
I'm trying to create a view that contains a list of checkboxes that is dynamically created from a database, and then retrieve the list of selected ones when the form is posted back.
My EF model contains a class:
public class ItemIWouldLikeACheckboxFor {
public int Id { get; set; }
public string Description { get; set; }
}
I...
I have a page that collects information on two objects of the same type. When the page is submitted the action that handles the processing of the information submitted is attempting to use model binding, something similar to:
public ActionResult Submit(Person parent, Person child)
{
//Do some stuff
}
It manages to bind one of th...