Swashbuckle for custom model binder - model-binding

In WebAPI (.net core 2.1) I've got a URL query string that has the format of &title=fred&author=blogs&sort=-title (etc.). I'm trying out various ways of model binding this into a single "facets" dictionary of , e.g "title","fred" etc. The most flexible to is use a custom model binder.
However when I use Swashbuckle the swagger UI shows a parameter of 'request' that takes a type object. I can enter my raw querystring in here but then this gets sent on the URL as &request=title=fred&author=blogs.
Is there a way to tell Swashbuckle to not send the &request on the URL but to just send the raw contents?

Related

How to Call webservice from contoller in mvc4?

I badly need your help. I need to bind xml to grid in mvc4 using jquery mobile. i got xml through web service in controller but no idea how to make the xml content to grid and whether i need to pass the xml content to model ? I searched in net but didnt get clear example.
If this is a ajax called request, you can return back the xml as response of request and use an API to parse XML via Javascript. With that, you deserialize the xml just one time. If you parse to object and return model, you will deserialize two times.
Consider use: http://api.jquery.com/jquery.parsexml/

Calling a web api method with custom object

Usually I send my post request with a custom parameter and a custom return and object using
HttpClientExtension.PostAsJsonAsync<T>
This allows my to call a post method with a custom object.
Now, I want to be able to send my custom object as a parameter and return value to a GET Method.
Lets say my method signature is
[HttpGet]
public MyMethodResponse MyMethod(MyMethodRequest request)
How can I send a request when I have an instance of MyMethodRequest ?
Thanks.
You need to encode MyMethodRequest onto the query string. You can either encode it as separate query string parameters or as a single one. You have handle the encoding yourself on the client side, remembering to URI-encode the parameters. Decoding is done using a custom ModelBinder or TypeConverter respectively. This article shows examples of binding a complex object on the query string.

How does one access and bind the entity meta-data (through JavaScript on the client) available from Upshot?

One of the supposed benefits of Upshot is its ability to query meta-data exposed through Data Annotations. How would one access meta-data for entity properties for things like string length, default values, display name, description information, and whether a field is required?
How would connect this data into a validation framwork like jQuery Validation or Knockout Validation?
Note: I am currently using Knockout 2.1.0, Upshot 1.0.0.2, Entity Framework 4.3, and ASP.NET MVC4.
You can use the upshot function metadata() to access this information, for example:
If you have the following upshot registration:
#(Html.UpshotContext(bufferChanges: true)
.DataSource<App.Controllers.DBController>(x => x.GetUsers())
.ClientMapping<App.Models.User>("User")
)
you can access the metadata (and validation rules) like this:
var metadata = upshot.metadata(upshot.type(User));
you can also retrieve information about properties (eg. "Name"):
var propertyType = upshot.metadata.getPropertyType(upshot.type(User), "Name");

JSON string from client to Struts 2 Action. How to handle just using struts.xml configuration

I ve a question. I have a JSON string ready to send to an Struts2 action from a ajax javascript function. Action is called properly, but i dont know how to get the JSON parameter from its method.
Is any struts.xml action configuration that makes me able to put automatically the information in the object, just as ..attributeClass?
In a similar way that i send from the server to the jqGrid (a javascript object to make grids with data inside, just with struts configuration result type=json and the attributes of the object that i want to send as a JSON string to the client web)?
Or maybe the only way is forget the struts.xml configuration and "hard programming" HttpServletRequest parameter, that has JSON string?
Thank you!
Both the JSON plugin and REST plugin can do what you want. Which makes more sense to use depends on the application.
You could do the work manually, either by accessing the request directly (not recommended), or by manually parsing a string parameter.

Silverlight and MVC: post object to controller method

I have an MVC project in which a controller action returns some JSON data (i.e. via /Home/GetData URL). This action also takes a custom object as a param.
This signature for the action is JsonResult GetData (MyCustomObject o)
I also have a client Silverlight project in which I'm constructing MyCustomObject and trying to call this URL (/Home/GetData/) via HttpWebRequest. However, I'm having trouble figuring out how to post in my object in this call. Do I need to serialize it to Json in order to pass it in?
Thanks so much!
MVC can accept and bind the submitted data to your MyCustomObject object, regardless of whether it is submitted as JSON, XML, a query string, a standard form POST, etc.
MVC does not require the object to be submitted in a particular fashion. That is up to you as the designer to determine what works best under the particular circumstances, given all of your requirements.
When submitted, MVC will use the ValueProvider suitable to the form of the data submitted, and the DefaultModelBinder will attempt to use the values in the ValueProvider to bind to your model.
Thanks for your help! Since the web app handles this with a getJSON call, I ended posting the object as a query string param i.e. I'm making a web request to http://../controller/action/view.aspx?custObject.property1=<value>&custObject.property2=<value> etc

Resources