Note that there are some explanatory texts on larger screens.

plurals
  1. POMass assignment using RestSharp, POST request - MVC3
    text
    copied!<p>I've been doing a lot of research trying to find the best way to communicate a mass assignment POST request with my ASP.NET MVC3 app without much success.</p> <hr> <p>Here's the scenario:<br> Like I mentioned, I have a ASP.NET MVC3 with standard REST methods, with which I'm trying to communicate with a desktop application (another app written in-house). To start with as a prototype, we just used the brute force XML document upload through <a href="http://msdn.microsoft.com/en-US/library/system.net.webclient%28v=VS.100%29.aspx" rel="nofollow">WebClient</a> and then having the MVC3 application parse through the XML document. In order to maintain this behavior we would have to be constantly building multiple methods, one for the XML document parsing, and one for standard model usage on the website. I'd like to stay away from that if I can.</p> <hr> <p>After all my research I came across <a href="http://restsharp.org" rel="nofollow">RestSharp</a> and I'm wondering if there is someway to handle mass assignment POST requests using RestSharp. I'd like to be able to do something like the following:</p> <p>In the MVC3 app...</p> <pre><code>public class RegistrationRequest { public string Email { get; set; } public string RequestedUserName { get; set; } public bool Register(string domain) { // Do registration stuff. } } public class AccountController : Controller { [Authorize,HttpPost] public ActionResult Register(IEnumerable&lt;RegistrationModel&gt; models) { return models.Any(model =&gt; !model.Register(this.Url.DnsSafeHost)) ? new HttpStatusCodeResult(400) : new HttpStatusCodeResult(200); } } </code></pre> <p>In the desktop app...</p> <pre><code>public class RegistrationRequest { public string Email { get; set; } public string RequestedUserName { get; set; } } public class RegistrationService { public void CreateUsers() { List&lt;RegistrationRequest&gt; registrations = new List&lt;RegistrationRequest&gt;(); // list of requested users built up by app var client = new RestClient(baseUrl); var request = new RestRequest("Account/Register", Method.POST); //request.AddAllMyObjects(registrations); var response = client.Execute(request); } } </code></pre> <p>Can anyone give me any pointers on how to achieve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload