I am trying to send some parameters with GET request to the controller in query string. I am getting all parameters that are inside query string to one Dictionary<string, string>
using [FromQuery]
. It is working well until one of the parameter name contains dot ( .
) sign. I checked Request.Query
object and it looks that it's parsed well but my Dictionary object get this one, exact item wrong. So it looks like bug in [FromQuery]
binder or i am doing something wrong. Code with debbuged values of Request.Query
and mine parameters
below:
This is how the query string that is sent looks like: ?query=&InspectionType=Safety&ItemType=InspectionPoint&RecordParentGUID=9275bee2-0a2d-461c-8835-51880e76f035&parent.ResultClassCode=parent.ResultClassCode
UPDATE: Got answer from Eilon Lipton working in .net developers team, in short - this is by design. Dot sign .
and [
, ]
are special ones used for denoting properties and indexers. Full answer available here: https://github.com/aspnet/Mvc/issues/6746
The . (dot), [ and ] characters are used everywhere internally by ASP.NET MVC Core as path separators in the model binding process and there is (AFAIK) no way around that.
If you want to access the raw values from the query string, Request.Query
is by far the simplest solution.
To turn it into a pure Dictionary<string, string>
:
Request.Query.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Can you use a partial view to flatten parent.ResultClassCode to ResultClassCode?
The partial could look like this
@model parent
<div class="form-group">
<label asp-for="ResultClassCode"></label><span asp-validation-for="ResultClassCode" class="text-danger"></span>
<input asp-for="ResultClassCode" class="form-control">
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.