Different Parameter Binding Priority For GET And POST?

Jan 12, 2011

Given this route:

routes.MapRoute("home", "{action}/{id}",
new { controller = "home", action = "index", id = UrlParameter.Optional });

...and this action:

public ActionResult Hi(string id) {
return Content("hello, id: " + id);
}

Question #1

What is the response for:

[URL]

Question #2

What is the response for:

[URL]

Content-Length: 4

Content-Type: application/x-www-form-urlencoded

id=3

I believe this is a bug and the route value should always have precedence, since the URL is what identifies a resource. If you write a POST, PUT or DELETE action you expect the id coming from the URL, not from the body of the request. This could cause changes to a different resource, and can be exploited by malicious users.

After doing some research found that the issue is the default ValueProviderFactory registration order, where FormValueProviderFactory comes before RouteDataValueProviderFactory. Instead of messing with the order I created a CustomModelBinderAttribute:

[code]....

View 2 Replies


Similar Messages:

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 :: 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

Check If Output Parameter Is Null Before Binding?

Jan 26, 2011

How can i check if an output parameter is null before i bind it to a asp literal, and if it is null i want to just make the literal

hname1.Text = cmd.Parameters("@hotel1").Value
hname1.DataBind()
hname2.Text = cmd.Parameters("@hotel2").Value

[code]...

View 1 Replies

MVC2 Model Binding Does Not POST Back Hidden Values?

Jul 25, 2010

I have a /Register [GET] Action in the controller that pre-poluates a view-model with a string and an integer and returns: return View(myModel);I can see the string being populated in the textarea and the id being populated in a hidden input. Yet when the form gets POSTed, the string value is null and the int value is 0. I verified that both values are posted to the server but the model received in the POST action is missing those values.

View 1 Replies

Binding View Model From A Form Post With Inner Complex Types?

Apr 15, 2010

[Code]....

What I want to achieve is the ID of the property: item.Item.ID to be bound to the ID from the (route)URL. However I can't get it to work. I tried using [Bind()] attribute.

I fixed it now using a hidden field in the form like so:

<%= Html.HiddenFor(model => model.Item.ID)%>

However this feels a bit icky. I'd like to know if there is a better cleaner way of doing this?

View 1 Replies

C# - Dynamic Grid View Loses Binding When Post Back Occurs

Sep 8, 2010

dynamic grid view loses binding when post back occurs ?

I have a dynamic grid View with template fields and bound fields as columns

for the first page load all binding looks fine.values are populated in all columns

when I trigger an event such as selected index changed in Drop downlist present in the column header(inside template field ) the binding are lost and the event is never catched.

how to retain controls when post back occurs and how to resolve this problem ?

View 2 Replies

MVC :: Saving A Complex Child Object After Post (LINQ To SQL Model Binding With MVC)

Jan 6, 2011

I am using ASP.Net MVC2 and LINQ to SQL. I am using DataAnnotations and model binding in conjunction with a Form/View and its working beautifully well. Loving that.. My view is an "Add new Employee" form that's adding a new "Employee" complex object. Every Employee also has a child complex object called an "Address".
I am using the bound Html helpers in the view, such as Html.TextBoxFor(model => model.NewEmployee.FirstName) for example. Working beautifully well, validating beautifully well both client and server and coming into the controller fully populated and ready to be saved! Exciting.. ModelState.IsValid returns true and I go to save the new Employee.

The Employee is created fine but the system also creates a blank/new Address record in my Addresses table even when the Address fields are blank! How can I prevent any Address from being created, in situations where I ONLY want to create a new Employee with no Address. An example is when the user supplies an existing Address, then I wish to simply set the new Employee's AddressID to that of an existing physical address (I hope that makes sense). But it could apply to any situation where you need to create a new complex object, but you don't wish for LINQ to create any of its child complex objects. I have tried setting NewEmployee.Address = null after it is received in the controller, but even after that, a blank/new Address is still created. Even if I try NewEmployee.Address = SomeExistingAddress, it does correctly link the Employee to the existing Address, but it STILL goes off and creates another redundant new/blank address record! Which is really weird..

View 10 Replies

MVC + LINQ To SQL Model Binding - Saving A Complex Child Object After Post

Jan 5, 2011

I have a "Create New Employee" ASP.Net MVC form. My complex object is an Employee and an Employee has an Address, which is another Complex object. On my View/Form I collect all required values for both the Employee and the Address. I'm using the bound HTML helpers such as: Html.TextBoxFor(model => model.EmployeeAddress.StreetName)

AND

Html.TextBoxFor(model => model.NewEmployee.FirstName)

This is all working beautifully well. Model binding is working like a dream, both server side and client side validation using DataAnnotations is working beautifully well and I am nicely receiving my populated complex objects as expected in the Controller.. Now I'm trying to save.. The Employee should always be newly created, because its an "Add New Employee" form. But sometimes the Address is an existing Address and I don't want to insert another one. Rather, I just want to link the Employee to the existing AddressID of the one that already exists in the database.

So I wrote a nifty GetExistingOrCreateNewAddress(Address PostedAddress) method which works great so I end up with the correct Address to use and link to the about to be saved Employee object. This is all happening in the same DataContext, so no problems there..

BUT even when I link the about to be saved Employee object to an existing Address, on save a new/empty Address row is created in my Addresses table. Even though the newly created Employee does link correctly to the existing Address I told it to! Why is it so??? And how can I save the new Employee without LINQ automatically creating a blank Address for me. Because I'm explicitly specifying an existing Address it should be linked to instead!

[HttpPost]
public ActionResult CreateEmployee(EmployeeDetailsViewModel NewEmployeeDetails)
{
if (ModelState.IsValid)
{
EmployeeRepository ER = new EmployeeeRepository();
// Fetch or Create the appropriate Address object for what has been entered
Address ActualAddress = ER.GetExistingOrCreateNewAddress(NewEmployeeDetails.EnteredAddress);
// Link this Address to the "about to be saved" Employee
NewEmployeeDetails.Employee.Address = ActualAddress;
// Lock it in..
ER.SaveNewEmployee(NewEmployeeDetails.Employee);

View 2 Replies

Is It Possible To Set Route Priority In Mvc 2 Using Arearegistration

Jan 19, 2010

Is it possible to set route priority in asp.net mvc 2 using arearegistration? I have a catch all {*pagePath} route which I want to set the lowest priority on.

View 1 Replies

.net - Ranking Priority Using DropDownList In C#?

Jan 26, 2011

My idea is to build a Ranking Priority using a DropDownList ASP server control.Here's my setup: I have 3 DropDownLists and it has 3 items ("First", "Second", "Third") on each DropDownLists. When I have chosen the 1st DropDownList assuming the item I have selected is "First" and on the 2nd DropDownList by default its SelectedItem is "First" also the item of the 1st DropDownList on which I have selected must be swapped on the 2nd DropDownList. In short there would be unique SelectedItems on each DropDownList and in every SelectedIndexChanged event occuring there would be swapping of items on the 3 DropDownLists. That's what my Ranking Priority would be.My question would be, how can I swapped a previous item on the DropDownList going from one another DropDownList where I have selected on and placed a new item?Here's my code:

protected void DropDownListPriority_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlRank = (DropDownList)sender;

[code]...

View 1 Replies

DataSource Controls :: Querystring Or Control Parameter In Sqldatasource Binding

Jan 21, 2010

after I pass querystring parameter to page,page works as expected,but after that when I change my control parameter(dropdownlist selected value how can I set querystring to null or empty...

View 1 Replies

Web Forms :: Multiple Validations On One Field - Set Priority

Dec 30, 2010

While develop some asp site i have problem with multiple validations on one field. I have input box and 3 validations for it.

- Required Field
- Compare Validation
- Regular Expression

how to set validations priority. Ex. If Required Field catch error, then Compare Validation and Regular Expression validation messages to be hidden. If Compare validation catch error (and Required field is ok- entered something) then validation message for Regular Expression to be hidden... etc etc...

[Code]....

View 4 Replies

Web Forms :: How To Set Priority On Html Mail Insead Of Plain

Apr 9, 2010

I got a issue with sending mail. The mail itself is made with plain text & html, it goes away good and all. Now the problem is that some get it like plain some get it like html. Like I tried to send one to myself on hotmail, It looked great was the html, seconds later I open it on my phone the same email address and there was the plain one. Some get the plain when looking on a computer to.How can I set priority on the html text instead of the plain? or is there a way?

Second I issue is that I can not send email to some mail's like any address with .pl in it. What could this possibly be? I should say that I do use my own winserver2008 and use the localhost smtp on it.

View 5 Replies

Web Forms :: Events With 2 Controls - Can Give A Priority At The Events

Oct 19, 2010

I have a page with 2 Controls, a ListBox and a DropDownList.

In the DropDownList you can select a PLACE.

In the ListBox you can see all DOCUMENTS for the selected PLACE.

If you select a DOCUMENT, the program does a redirect on the selected DOCUMENT.

So, there are an AutoPostBack and an Event (if you select another Item) on both Controls.

The problem is: If I select a PLACE, then I select a DOCUMENT (the pdf document is opened), and then I go back on the page and I want to select another PLACE, the program doesn't select another PLACE, but opens the old DOCUMENT, because there are 2 Events, one to change the PLACE and one to open the DOCUMENTS.

Can I give a priority at the Events?

View 1 Replies

Social Networking :: Post Tweets To Twitter Account And Post To FaceBook Wall?

Aug 6, 2012

code to integerate twitter and facebook in my application,

View 1 Replies

C# - What's The Difference Between Binding Data To The Repeater In The Mark-up Or Binding It Programatically

Mar 4, 2011

What's the difference between binding for example a column called ("Name") in both cases ? and is there's any performance difference ?1- Assigning the data in the mark-up

<asp:Label ID="Name_Lbl" runat="server" Text='<%# Eval("Name") %>' ></asp:Label>

2- defining a control object for every control inside the repeater ItemTemplate and find it and then assign the data in the column "Name" to ite.Item.FindControl("Name_Lbl")

View 2 Replies

SQL Server :: Post That Have DateCreate 2010-12-01 There Is No Post Deleted?

Dec 20, 2010

I have this SP.When I run it and there is no post that have DateCreate 2010-12-01 there is no post deleted but there is no error catched.

[Code]...

View 4 Replies

Difference Between Static Binding And Dynamic Binding?

Dec 17, 2010

May I know what is the diffrence between static binding and dynamic binding and which binding is used in

1)Virtual Functions

2)Abstract Class

3)Function Overloading

4)Operator Overloading

5)Fuction Overriding

6)Delegates

View 1 Replies

C# - Post The User Text To The Server Using $.post()?

Mar 16, 2011

im updating my page using jQuery/javascript once a user types something.

<script type="text/javascript">
$(function () {
$('button').click(function () {
var x = $('textarea').val();
$('textarea').val('');
$('#test1').append('<div id="test">' + x + '</div>');
return false;
});
});
</script>
<textarea style="border: 0" cols="77" rows="2">.......

View 1 Replies

SQL Reporting :: MDX Query Parameter From SSRS / Setup @from And @to As Parameter But Not Working?

Aug 21, 2010

I've a MDX Query that has where clause as shown below.I'm designing report using SSRS 2008. How can i pass date as parameter? I tried to setup @from and @to as parameter but not working?

WHERE ( {[Date Central].[Calendar Date].[2010-04-01 00:00:00]:[Date Central].[Calendar Date].[2010-08-30 00:00:00]} )

need it to work as
WHERE ( {[Date Central].[Calendar Date].[@From]:[Date Central].[Calendar Date].[@To]} )

View 1 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

SQL Reporting :: Parameter Enabling Based On Selection In Another Parameter?

Nov 12, 2010

I have a parameter Owner with 1,2,3 options in dropdown.

On selection of option 1 , a country parameter should be enabled with all countries' values defaulted.

Option 2 should enable Region parameter with all the Regions values selected and country parameter should be displayed.

Option 3 should disable both Region & Country Parameter.

I am using SSRS 2005 with Enesys tool as add on.

View 2 Replies

SQL Reporting :: Create Another Parameter That Acts A Filter For The Other Parameter?

Jun 26, 2010

One of our customers has a report with a single value string parameter that has over 1000+ possible values. selecting single value from 1000+ choices results in bad UI, among other things.create another parameter that acts a filter for the other parameter. So you would have Param1 with say 25 choices and selecting a choice would narrow down the option for the second parameter.Is this the best way. What is the best practice for handling these kinds of parameters?

View 5 Replies

Forms Data Controls :: Setting The ID Parameter To Form Parameter Source And Have Entered The Grid Views Name In The Form Field

Mar 11, 2010

How do you use the http POST method with a Grid View on another page. I am trying to use the POST method to send the ID from the selected row of a Grid View, I am using a link button set to fire the select command and it has the Post Back URL set, from one page and then retrieve the ID value on another page using an Object Data Source. Also, under the Defining Parameters, I am setting the ID parameter to Form Parameter Source and have entered the Grid Views name in the Form Field.

View 4 Replies







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