MVC :: Bug - Get Value From Route Parameter Instead Of Property Of Model

May 18, 2010

I found little bug feature in MVC 2.

So, if we have in route defined parameter with same name as property at model and then we call it from strongly typed HTML helper (for example Html.TexBoxFor(x => x.PropertyName)), we get value from route parameter instead of property of model.

For example.

We have defined follow route:

[Code]....

Very simple model:

[Code]....

Next action in controller:

[Code]....

And very simple view:

[Code]....

Result you can see at follow picture:

I think what this dirty example described the essence of the problem. Let me know if I'm wrong.

View 1 Replies


Similar Messages:

Generate A Path - Url From A Route Within A Model Class?

Nov 26, 2010

How to generate a path/url from a Route in the Routes table? only this time I'd like to be able to build a url within one of my Model (partial) classes. I'm defining a new property that will contain the text to be rendered within an rss feed, and want to inser urls (within anchor tags) in this text. I found the UrlHelper.GenerateUrl method, but get unstuck once I get beyond passing in the appropriate RouteName, ActionName and ControllerName.

View 1 Replies

MVC :: A Catch-all Parameter Can Only Appear As The Last Segment Of The Route URL?

Mar 26, 2010

I have this dynamic url and part of it will going to have paging enabled ike, "http://localhost:96556/MVC_Application/proceedings/url_link/url_section/url_item/url_position/page/2"But I'm getting this error at my route below "A catch-all parameter can only appear as the last segment of the route URL.Parameter name: routeUrl"

routes.MapRoute( _
"UrlItemProceedings", _
"proceedings/{*catchPath}/page/{page}", _

[code]...

View 2 Replies

SQL Reporting :: Change Parameter Property After Selecting Another Parameter?

Oct 19, 2010

Is it possible to change a parameter's property after the uer has made a selection or filled in another parameter field? I'm using VS2005

Case:

- 3 parameter fields; Country,Station,Carrier all three are textfields and are allowed to stay 'blank'.

- When the user enters a Country-code in the 'Country' parameter field, the 'Carrier' parameter should become a required field.

I did some searching on the net, but haven't found the solution. I started to wonder if it's actually possible?

View 6 Replies

Getting Null Parameter Value In Controller When MVC Route Fires?

Jan 12, 2011

I'm using a custom route to create the following URL (http://mysite/subscriber/12345) where 12345 is the subscriber number. I want it to run the ShowAll action in the Subscriber controller. My route is firing and using Phil's route debugger, when I pass in the above url, the route debugger shows ID as 12345.

My controller is accepting an int as subscriberID. When it fires, the controller throws the error "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32". Why does the route debugger show a value and the controller doesn't see it?

Here's my route (first one is the culprit)

routes.MapRoute(
"SubscriberAll",
"subscriber/{id}",
new { controller = "Subscriber", action = "ShowAll", id=0 },
new { id = @"d+" } //confirm numeric
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

I'm getting a null in the ShowAll action? Here is the action method signature:

public ActionResult ShowAll(int id)

View 3 Replies

Custom Route With More Than One Parameter In Url (customer - Extra Info)

Jan 31, 2011

I have a multi tenant system and I need to allow administrators to edit the information of other customers. I believe the correct way to do this is to append the customer ID to each request, and update my routes accordingly. How do I make ASP.NET accept and use something like this in the controller (order doesn't mean much to me): [URL] and how would I pass and consume that in my controller? The ASP.NET tutorials skip this... (or I don't know where to search)

View 1 Replies

MVC Routes Adding An Optional Parameter At The Beginning Of A Route

Aug 7, 2010

I have the following routes setup in my route config file. I have a config reader that maps these to MVC-style routes.

[route name="customers" url="customers/{statename}/{marketname}/{pagenumber}"]
[controller name="Customers" action="Display" //route]
[route name="pcustomers" url="{customername}/customers/{statename}/{marketname}/{pagenumber}"]
[code]...

View 2 Replies

MVC :: Route Parameter Reversed On Form Submit Button Click?

Jan 25, 2011

As the title says when I click the submit button on my form, instead of taking me to the next form with a url of controller/action/id or /action/id I am getting a nice 404 with a url of /id/action

The offending action is called IntakePage2. Typing the correct route manually works.

My routes are as follows:

[Code]....

The relevant controller code is as follows:

[Code]....

The partial that IntakePage1 loads:

[Code]....

<%}%>

IntakePage2 main page (The partial it references just has the text "boo" in it at the moment. It is intended to take an InsertViewModel object at some point.)

[Code]....

View 3 Replies

How To Pass JavaScript Function As A Parameter In The Route Values Of Ajax Actionlink

Apr 20, 2010

I need to pass javascript function as a parameter value to the ajax actionlink in asp.net mvc app. how can we achieve this?

View 1 Replies

C# - MVC - Binding Of Parameter To Model Value?

Jun 14, 2010

This seems like the model binding is causing me issues.Essentially I have a model called ProductOption and for the purpose of this question it has 2 fields

ID (Int) PK
ProductID (Int) FK

I have a standard route set-up

context.MapRoute(
"Product_default",
"Product/{controller}/{action}/{id}",

[code]...

This is used to determine (on submit) if we are editing or adding a new option. However the Model binder in .net seems to replace .ID (Which was 0 when leaving the above get actionresult) with 1 (or the value of the id parameter in the URL)How can I stop or work around this?

ViewModel
public class ProductExtraModel
{
//Database
public int ID { get; set; }
public string Name { get; set; }
public int ProductID { get; set; }
public ProductModel Product { get; set; }
}

View 2 Replies

MVC :: Model With Parameter In The Constructor?

May 14, 2010

I have the following constrcutors within a Model and I want to click the create button on a previous view and pass the projectID in and call the second Constructor so I have the projectID on this view. Do I need to change the routing in someway to call the constructor with the parameter? -

[Code]....

View 2 Replies

MVC :: Post Action Model Parameter

Jan 26, 2011

i wonder something about mvc post method. for example I created a view "strongly typed" from a model (MyModel).

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Demo1.Models.MyModel>" %>
for Create actionsthere is two way.
first one takes MyModel as parameter
[HttpPost]
public ActionResult cart(MyModel md, int someID)
{
//some code
//.....
return View(MyModel);
}
second one does not take parameter as model.
[HttpPost]
public ActionResult cart(int someID)
{
//some code
//.....
return View(Mymodel);
}

for first one way, after form post the form values does not delete, I mean form does not cleared,after second one form is be cleared. why this diffirence?

View 5 Replies

MVC :: Getting The ID For A Model Property From HTML Helper

Jan 25, 2011

Is there a way to retrieve the client side ID for a model property similar to how the helpers like LabelFor etc generate the ID? For example, I have a model with a DateOfBirth property. I want to hook up that field to a jQuery DatePicker. Normally, I would hook up the date picker like this:

[Code]....

This works fine but hard codes the DateOfBirth property name. Ideally, I would like to use this:

[Code]....

Is this already available out of the box somewhere? I just created an extension method on the HtmlHelper class that does exactly this, but I wondered if there was already something built-in so I don't have to reinvent and test the wheel.

View 10 Replies

MVC :: View Model Property Become Null?

Nov 8, 2010

So I have code as below

public ActionResult Create(AccountClassificationCreateViewModel ACCVM)
{
if (ACCVM.newMtn0130 == null)//Why ACCVM.newMtn0130 is null after [code]...

I wonder why the ACCVM.newMtn0130 become null after RedirectToAction? I already assign with "_ACCVM.newMtn0130 = newMtn0130".

ACCVM._Error didn't become null after RedirectToAction.

View 5 Replies

MVC :: UpdateModel Calls A Property Get On The Model?

May 4, 2010

as the behaviour of the UpdateModel<T> changed in MVC 2 (RTM)? Since then I have the following problem when UpdateModel is called:UpdateModel<T1>(record, properties);record is typeof(Jumbo.Juist.Models.Bezorging) and properties is a string[] containing "Winkelnummer" and "OudRoutenummer".This now fails, because a get-property is being accessed: BerekendeAankomstTijd. In the past, it didn't fail. IMHO, this validation should be skipped, because it's only a getter (and thus/also not included in the string[] of properties to update)

View 14 Replies

MVC :: How To Display Property Of Model On View

Aug 26, 2010

How can I show display property of Model on View.

public class Model
{
[Required]
[DataType(DataType.Text)]
[DisplayName("First Name")]
[code]...

View 6 Replies

MVC :: Validation With Model As Property To ViewModel?

Jan 11, 2011

I have a viewmodel with a property of a model class type. I set some properties in the model class to be able to show it to the user but then when I make a post, the model gets validated. How to overcome this? I don't want to enforce the DataAnnotations contraint in this case....

public class TheViewModel
{
TheModel TheModel { get; set;}
}
[code]...

View 1 Replies

MVC :: Parsing Model Error - Object Does Not Have Property Name?

Sep 18, 2010

Action:

[Code]....

View:

[Code]....

But error raised "object does not have property Name". Why?

View 4 Replies

MVC :: How To Exclude One Of Model's Property From The Html.EditorFor

Sep 10, 2010

I would like to exclude one of model's property from the Html.EditorFor. I tried [HiddenInput(DisplayValue=false)] but it renders the property as an hidden input. This could potentially be a security problem. How can we completely exclude a field from Html.EditorFor?

View 5 Replies

MVC :: Set Radio Button Selection From Model's Property

Oct 11, 2010

I got 3 radion-buttons on the view called:

- Taxi
- Train
- Bus

The model passed has a property called "Transport" of type String. In the action, if I set the property as 'Train', then the view should set the radio-button 'Train' checked. ie.

Action:
model.Transport = "Train";

How do I do that in the view to make the radio-button Train checked?

View 2 Replies

C# - MVC - Using Model Property As Form - Post To Action?

Jan 12, 2011

public class BandProfileModel
{
public BandModel Band { get; set; }
public IEnumerable<Relationship> Requests { get; set; }
}
and the following form:
<% using (Html.BeginForm()) { %>
<%: Html.EditorFor(m => m.Band) %>
<input type="submit" value="Save Band" />
<% } %>
which posts to the following action:
public ActionResult EditPost(BandProfileModel m, string band)
{
// stuff is done here, but m is null?
return View(m);
}

Basically, I only have one property on my model that is used in the form. The other property in BandProfleModel is just used in the UI for other data. I'm trying to update just the Band property, but for each post, the argument "m" is always null (specifically, the .Band property is null). It's posting just fine to the action, so it isn't a problem with my route. Just the data is null.

The ID and name attributes of the fields are BAND_whatever and Band.whatever (whatever being a property of Band), so it seems like it would work. What am I doing wrong? How can I use just one property as part of a form, post back, and have values populated via the model binder for my BandProfileModel property in the action?

View 2 Replies

MVC :: Assigning A Cssclass Based On A Model-property?

Dec 6, 2010

I want to assign a stylesheet-class to a <div> element. The cssclass I want to use depends on the property 'Level' which is defined in de ViewModel.

I want to have something like this:

<div class="dashboardlevel" + <%= Model.Level %>>

But this doen't work.

View 2 Replies

Get DisplayName Attribute From MVC2 Model's Property?

Dec 28, 2010

So, I've got an contact form in my MVC 2 application.

I'd like to programatically email all properties of my "ContactModel".

Here is what I'd like to do in psuedo-ish code:

[Code]....

In case it matters...ContactModel sets up the DisplayName attributes like this:

[DisplayName("First Name")]
public string FirstName {get; set ;}

I'd like to keep this nice and DRY by not repeating the DisplayName names.

Specifically, I'd like to enumerate over each property in my ContactModel, get its DisplayName, and get its submitted value.

View 1 Replies

MVC :: HttpRequestValidationException After Using [SkipRequestValidation] Attribute On Model Property?

Nov 12, 2010

I think I might have stumbled onto a bug in ASP.NET MVC 3 RC. When I setup my MVC2 project in a new MVC3 project, copy paste classes, code, change name spaces, etc, etc, I ran into an issue in the following, simplified for explanation purpose, scenario:

Model:

public class WineDetails
{
[SkipRequestValidation]
[Required(ErrorMessage = "Beschrijving verplicht")]
public string Description { get; set; }
}

ViewModel:

public class ViewModelCreateWine
{
public MasterData MasterData { get; set; }
public WineDetails WineDetails { get; set; }
}

ActionMethod:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateWine(ViewModelCreateWine viewModelCreateWine)
{
GetMasterDataRegions(viewModelCreateWine);
if (Request.Params.ToString().IndexOf("Save") > 0)
{
if (TryValidateModel(viewModelCreateWine.WineDetails))
{
m_wineService.CreateWine(viewModelCreateWine.WineDetails);
return RedirectToAction("index", "Admin");
}
}
return View(viewModelCreateWine);
}

The ActionMethod "CreateWine" needs to call the "CreateWine" method in the WineService so that in the end a new Wine is added to the Database. So far it looks ok. As shown in the above code the [SkipRequestValidation] is set on the "Description" property of the WineDetails model so that the user can add Rich Text to the description and HTML elements are allowed during the Request validation. This works perfectly fine until the Params collection of the Request is accessed in the code to check if the Save button is clicked. When this line of code is trying to execute the following exception is thrown:

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ViewModelCreateWine.WineDetails.Description="<p>HTML Content with...").

The same exception is thrown when I put the [ValidateInput(false)] attribute on the action method. When I comment out the "if" statement and its content there is no issue and the model validation works just fine and skips the Request Validation on the Description property as expected.

In MVC2 the above code worked fine with the [ValidateInput(false)] attribute on the action method.As I said I'm not sure if this is a bug, it very well might be my own stupidity, but I thought it would be worth to mention here. So any feedback is more than welcome.

View 2 Replies

MVC :: Bind ActionResult IEnumerable Property In Model?

Nov 23, 2010

How I can bind in my ActionResult IEnumerable property in Model.

Objects:

public class Project
{
public int ProjectID {get;set;}
public IEnumerable<Category> Categories {get;set;}
}

[Code]....

View 15 Replies







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