Using MVC2 EditorTemplate For DropDownList?

Apr 29, 2010

I've spent the majority of the past week knee deep in the new templating functionality baked into MVC2. I had a hard time trying to get a DropDownList template working. The biggest problem I've been working to solve is how to get the source data for the drop down list to the template. I saw a lot of examples where you can put the source data in the ViewData dictionary (ViewData["DropDownSourceValuesKey"]) then retrieve them in the template itself (var sourceValues = ViewData["DropDownSourceValuesKey"];) This works, but I did not like having a silly string as the lynch pin for making this work.

[code]...

View 3 Replies


Similar Messages:

C# - Populating Dropdownlist Using MVC2 Based On Another Dropdownlist (Cascading)

Sep 18, 2010

I am making an application that deals with vehicles. I need two DropDownLists:

Makes: All Vehicle Makes
Models: Models that belong to the selected value of the Make DropDownList

How is this done in MVC2? My Idea: Do I use an ajax call when my first list is selected and then pull back the Models to bind to the Model DDL? How would model binding come into play that way? UPDATE I posted what I ended up doing as an answer. It is super simple and works great. You can use a get too if you feel so inclined, but you have to specify that you want to like so... return Json(citiesList, JsonRequestBehavior.AllowGet);

View 4 Replies

MVC :: How To Use The EditorTemplate

Jan 12, 2011

I read that EditorTemplates are loaded automatically, but from asp.net mvc 2 and now 3 with razor, I still cant get this to work.

My model looks like this:

[Code]....

My view looks like this:

~/Views/Roles/Edit.cshtml

[Code]....

~/Views/Roles/EditorTemplates/RoleViewModel.cshtml

[Code]....

If i move the content from the

[Code]....

to the actual page, then it works, it shows the checkbox, etc. But with this current setup, all that shows up is the count of the number of roles.

What am I doing wrong?

View 3 Replies

MVC :: How To Bind Dropdownlist Using Stored Procedure In Mvc2

Feb 24, 2010

i have a stored Procedure , it gets all units(column) values from database. so i need to bind dropdownlist with units , i called Sp like this

[Code]....

is it right way or is any other way instead of dataset? if i use dataset how can i bind dropdownlist

View 1 Replies

MVC :: DisplayTemplate And EditorTemplate Naming?

Feb 23, 2010

I've got a couple of questions about the naming convention for the DisplayTemplates and EditorTemplates in MVC 2.

If for example I have a customer object with a child list of account how do I:

Create a display template for the list of accounts, what is the file called?When I'm doing a foreach( var c in Model.Accounts ) how do I call a display temple while in the foreach? When I do Html.DisplayFor( x => x ) x is the model and not in this case "c".

View 1 Replies

C# Mvc2 Encode Url?

Oct 8, 2010

i'm trying to encode an url with the code below;

var encodedUrl = HttpUtility.UrlEncode("http://www.example.com");
var decodedUrl = HttpUtility.UrlDecode("http%3A%2F%2Fwww%2Eexample%2Ecom%2F");

I'm working with the google webmaster tools api and this api expects an URL as shown in the decodedUrl variable above. Every single character is encoded there.

When i use the httputility encode function i get the following result;[[URL] How can i use the encoding variable in such a way that every character in the url is encoded?

View 2 Replies

Update A ViewModel In MVC2?

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

Possible Update To MVC3 From MVC2 Web App

Feb 8, 2011

I tried upgrading the solution to MVC3 in VS2010 by using an upgrader tool I don't know what it does exactly but it didn't work. My "System.Web.Mvc" is not being recognized in my project. Is there anything specific I should be doing with my web.config? I don't quite understand the underlying details about all the places I should be referencing dll's or what "binding" even means and when I should use it inside the web.config So I have to ask, what is the best method for upgrading to MVC3 and what have you done that works?

View 1 Replies

How To Use And/or Localize DisplayAttribute With .NET MVC2

Mar 25, 2010

I am trying to figure out how to get the DisplayAttribute in my MVC 2 ViewModel to work with the Html.LabelFor() helper.

Neither

public class TestModel
{
[Display(ResourceType = typeof(Localization.Labels))][code]...seem to work. Localizing the Required Attribute works as expected:

[Required(ErrorMessageResourceName = "Test", ErrorMessageResourceType = typeof(Localization.Labels))]


I am using VS2010 RC. Has anybody got that running?

View 3 Replies

Connectionstring Encryption In MVC2 4.0 App?

Nov 16, 2010

I have an MVC2 .NET 4.0 app, hosted on TFS 2008 (soon to be TFS 2010) that uses connection strings in web.config to connect to a database on another server. I need to encrypt these connection strings.

As I understand it, I can use aspnet_regiis.exe to encrypt the connectionstring portion of the web.config file, but I have to do it on the deployment machine because the encryption uses the machine name to generate the encryption key.

Now, it seems to me that this represents a problem - every time I deploy my code to the dev server won't it overwrite the web.config file, and need to be re-encrypted? This sort of manual process seems kludgy.

Is my understanding about needing to re-encrypt after deployment correct? If so, is there some way to automate this process? I don't want to forget this or get a new team member who doesn't know the process and have the connectionstring exposed to the world.

View 1 Replies

C# - MVC2 : Is It Possible To Make Own Model, Without Ado.net

Jun 28, 2010

For my project, i need to connect to a database who don't support ADO.net by using NHibernate

So, is it possible to make my own model who can be usable by the auto-creation of views of visual studio 2010 ?

View 2 Replies

How To Write MVC2 Validation

Mar 3, 2011

I have this code in my view page.

<td>
Mandate Name:
</td>
<td>
<%= Html.TextBox("MandateName")%>
</td>

I wrote MVC2 Validation for this name.

something like this.

//[Validator(typeof(MandateValidator))]
[MetadataType(typeof(Mandate_Metadata))]
public partial class Mandate {
public class Mandate_Metadata
{.........

View 2 Replies

Add A MVC2 And SiteMap Provider

Apr 24, 2010

I've tried this guide: http://mvcsitemap.codeplex.com/Thread/View.aspx?ThreadId=208090I've added dll "MvcSiteMap.Core.dll" i referencesAnd I've added namespaces in web.config: "<add namespace="MvcSiteMap.Core" />"When I'm entering the web page comes this message:

Line 49: </runtime>Line 50: Line 51: <siteMap defaultProvider="MvcSiteMap">Line 52: <providers>Line 53: <add

View 3 Replies

MVC2 Development Without Doing Enough Research About The EF4?

Sep 30, 2010

have starting doing a lot of MVC2 development without doing enough research about the EF4. This lead me to a path which I am not happy with. The way that I laid out my project is that my Models are all ADO.NET Entity Framework Models. Each model is representing database able. Today, I attempted to do a LINQ join on entities which belong to two different data contexts. This resulted in a nasty LINQ error telling me that it can't be done. I hate the fact that the only viable way to use the EF seems to create large models.

View 13 Replies

MVC2 : Use Radiobuttons In A Grid?

Apr 24, 2010

Again a question about RadioButtons/ RadioButtonList

I've the following Model:

public class SkillLevelModel
{
public long? Id { get; set; }
public int? SelectedLevel { get; set;}
}
I've the following Controller:
public class SkillController : BaseController
{
public ActionResult Index()
{
var skills = new List<SkillLevelModel>();
for (int i = 0; i < 10; i++)
skills.Add(new SkillLevelModel() { Id = i, SelectedLevel = new Random().Next(0,5) });
return View(skills);
}

I've the following code in the View:

<% foreach (var item in Model) { %>
<tr>
<td style="width: 30px" align="center">
<%= Html.Encode(item.Id) %>
</td>
<td>
<% Html.RenderPartial("UCSkillLevel", item); %>
</td>
</tr>
<% } %>

I've the following code in the PartialView:

<% for (int i = 0; i <= 5; i++) { %>
<td align="center">
<%= Html.RadioButton("SelectedLevel", i, new { id = Model.Id + "_" + i })%>
</td>
<% } %>

The problem is that no radiobutton is checked, althought they have a level.

View 2 Replies

C# - DDD Architecture For ASP.NET MVC2 Project

Oct 24, 2010

I am trying to use Domain Driven Development (DDD) for my new ASP.NET MVC2 project with Entity Framework 4. After doing some research I came up with the following layer conventions with each layer in its own class project:

[code]...
Currently my Repositories layer holds a reference to the Domain layer.From my understanding injecting a UserRepository to the UserService class works very well with unit testing as we can pass in fake user repositories.So with this architecture it looks like my Web project needs to have a references to both my Domain and Repositories layers.But is this a valid?Because historically the presentation layer only had a reference to the Business Logic layer.

View 3 Replies

MVC :: Integrating MVC2 And WebForms?

Jul 26, 2010

I have combined a MVC2 project with a WebForms project....however I found that the only way to do this was to create a base MVC2 project and then start dropping the WebForms project into the MVC2 project.If I do the reverse .....start with a WebForms project I cannot get the MVC2 functionality to work. For example ....if I right-click and attempt to Add an item.....I do not see the option to Add a MVC2 Area.

Obviously....since the WebForms technology is older ....it is more logical to start with a WebForms and somehow enable MVC2 within the WebForms project.I have read all the popular Internet posts on this topic....Hanselman, etc....and while this may have worked prior to VS.NET 2010 release....I cannot get it to work. As I say....the right click Add/Item/Area is not available in my project after I add the MVC2 references and create the MVC2 folders ...(Controllers, Models, Views, etc)....so I found the safest thing to do was to start from a base MVC2 project.

View 3 Replies

Serious Error Wrt RegularExpressionAttribute On MVC2 RC1?

Jan 25, 2010

If I decorate my model with a regular expression + localized string resource, and the ErrorMessageResourceName does not resolve to something on the object, the following things happen:

The regular expression is ignored altogether from a validation perspectiveNo error messages are raised in the MVC application.I would love it if the framework floated an exception in this instance because exclusion of this rule could have far reaching implications.The following is a modification to the ChangePasswordModel.NewPassword property in the stock MVC 2 RC1 project that exhibits the behavior. Note that while the MyResources does exist in my project, the EMResourceName does not exist on it.

[Code]....

[RegularExpression(@"^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$", ErrorMessageResourceType = typeof(MyResources), ErrorMessageResourceName = "InvalidPasswordMessage2")]

View 3 Replies

Where To Find Documentation Or Tutorials On MVC2

Mar 31, 2010

It looks like the final release for ASP.NET MVC 2 has been already around for 2 weeks. Unfortunately, I can't find documentation that's intended for MVC 2 exclusively. I've checked Amazon.com (no book yet on MVC2), ScottGu's Blog (only 2 short posts), ASP.NET/MVC website (they've only posted what are alreadi in the ScottGu's blog).

View 4 Replies

How To Connect MySQl To MVC2 Application

Mar 1, 2011

how can i connect mySql to my mvc application

i need a tutorial and all steps to connect to mySQL

View 1 Replies

C# - MVC2 - ViewModel For A Polymorphic Class

Jan 7, 2011

I'm making an MVC2 app to manage billing schemes. These billing schemes can be of various types, e.g. daily, weekly, monthly, etc. and all types have their specific properties. My class structure looks like this:

public abstract class BillingScheme { /* basic billing scheme properties */ }
public class BillingSchemeMonthly : BillingScheme
{
public string SpecificMonths;
}
//etc. for other scheme types

I retrieve a billing scheme through the base class using the billing scheme ID, and it gives me an object of the correct type. The property SpecificMonths maps to a database varchar field that contains a ;-separated string of month numbers. I want to split this to an array so I can create a list of checkboxes and I'd preferably do this with a facade property in a viewmodel. I could do it right inside the view but that seems to go against the MVC pattern.

The problem is I can only create this viewmodel specifically for a BillingSchemeMonthly, and I can't cast a BillingSchemeMonthly to a BillingSchemeMonthlyViewModel. I'd rather not implement a clone method in the viewmodel since the entire billing scheme is quite large and the number of properties may grow.

View 2 Replies

Display And Update Data In MVC2?

Mar 7, 2010

Table Product
Product Id
Product Name
Table ProductSupplier
ProductSupplierId
ProductId
SupplierId
Table Supplier
SupplierId
SupplierName

I have the above 3 tables in my database, ProductSupplier is the lookup table. Each Product can have many suppliers. I am using Entity Framework. Using Web Forms it was fairly easy to display a Product on a web page and bind a repeater with the suppliers information. Also, with Web Forms it was easy to Add new Product and suppliers, the linkage seemed easy.

How do you do this sort of functionality in MVC? In the Create View below, I want to be able to Add the Supplier as well. Is there a better approach that I might be missing here? This is how I did it with Web Forms. Beyond the code below I am totally lost. I can show data in a list and also display the Suppliers for each Product, but how do I Add and Edit. Should I break it into different views? With Web Forms I could do it all in one page.

namespace MyProject.Mvc.Models
{
[MetadataType(typeof(ProductMetaData))]
public partial class Product
{
public Product()
{
// Initialize Product
this.CreateDate = System.DateTime.Now;
}
}
public class ProductMetaData
{
[Required(ErrorMessage = "Product name is required")]
[StringLength(50, ErrorMessage = "Product name must be under 50 characters")]
public object ProductName { get; set; }
[Required(ErrorMessage = "Description is required")]
public object Description { get; set; }
}
public class ProductFormViewModel
{
public Product Product { get; private set; }
public IEnumerable<ProductSupplier> ProductSupplier { get; private set; }
public ProductFormViewModel()
{
Product = new Product();
}
public ProductFormViewModel(Product product)
{
Product = product;
ProductSupplier = product.ProductSupplier;
}
}
}
ProductRepository
public Product GetProduct(int id)
{
var p = db.Product.FirstOrDefault(por => por.ProductId == id);
p.ProductSupplier.Attach(p.ProductSupplier.CreateSourceQuery().Include("Product").ToList());
return p;
}
Product Create View
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyProject.Mvc.Models.ProductFormViewModel>" %>
<%= Html.ValidationSummary("Please correct the errors and try again.") %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.Product.ProductId) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Product.ProductId) %>
<%= Html.ValidationMessageFor(model => model.Product.ProductId) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Product.ProductName) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Product.ProductName) %>
<%= Html.ValidationMessageFor(model => model.Product.ProductName) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Product.Description) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Product.Description) %>
<%= Html.ValidationMessageFor(model => model.Product.Description) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>

View 1 Replies

C# - Update A Partial View From Another - MVC2

Sep 20, 2010

I want to have two partial views, one for SEARCH and one for SEARCHRESULTS. I want to update SEARCHRESULTS when the "Search" Button is clicked on the SEARCH partial view form. SEARCHRESULTS needs to have the form data fed to it from the SEARCH partial view. I'm not totally sure how to go about this. Can I update the SEARCHRESULTS partial view from my SEARCH partial view's Controller action?

View 1 Replies

MVC2 - How To Return A File From A Controller

Nov 23, 2010

Possible Duplicate: How to create file and return it via FileResult in ASP.NET MVC?

ASP.NET MVC2: How to return a file from a controller? I want to do this so the user can download the file from server.

View 1 Replies

MVC2 - How To Mask A Simple Dot In A String

Aug 20, 2010

This works fine: Controller.cs

ViewData["MyText"] = "Hello World";
Index.aspx
<%: Html.Label(ViewData["MyText"].ToString()) %>

But the complete text is not displayed when I add just a dot "." to "Hello World". I thought "<%:" takes care for this but it seams that this is not true... How to solve this? How to mask the dot? Changing "." with "%2E" doesnt work ;-(

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved