Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Issue: ParameterBinding attribute decorated on a type is not being applied to the derived types. [633]

$
0
0
Scenario: User wants to provide strongly typed properties for the input odata action parameters.

Workaround: decorated the binding attribute on the derived types too.

Action definition
-----------------
ActionConfiguration extendSupportDateProduct = modelBuilder.Entity<Product>().Action("ExtendSupportDate");
extendSupportDateProduct.Parameter<DateTime>("newDate");
extendSupportDateProduct.Returns<bool>();


Request
-------
POST /Products(1)/ExtendSupportDate HTTP/1.1
User-Agent: Fiddler
Host: localhost:50231
Content-Type: application/json;odata=verbose
Content-Length: 33

{"newDate":"2001-10-25T00:00:00"}


Custom Odata Action params
--------------------------
public class ExtendSupportDateParams : ODataActionParameters
{
public DateTime? NewDate
{
get
{
if (this.ContainsKey("newDate"))
{
return Convert.ToDateTime(this["newDate"]);
}

return null;
}
}
}

Does not work (ModelState is invalid and parameters is null)
--------------------------------------
public bool ExtendSupportDate(int boundId, ExtendSupportDateParams parameters)
{
if (!ModelState.IsValid)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
}

return true;
}


Works (ModelState is valid and parameters has request supplied 'newDate' value)
---------------------------------------
public bool ExtendSupportDate(int boundId, ODataActionParameters parameters)
{
if (!ModelState.IsValid)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));
}

return true;
}

Expected:
Model state should be valid and parameters should be populated in case of the derived type of ODataActionParameters type "ExtendSupportDateParams" as ODataParameterBindingAttribute has inherited attribute on it.
Actual:
Model state is invalid and parameters is null


Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>