در کد زیر [ActionName("Complex")] یعنی چه؟ اگر معادل vb.net رو هم میتونید چیه بهم بگید؟
[HttpPost] [ActionName("Complex")] public HttpResponseMessage PostComplex(Update update) { if (ModelState.IsValid && update != null) { // Convert any HTML markup in the status text. update.Status = HttpUtility.HtmlEncode(update.Status); // Assign a new ID. var id = Guid.NewGuid(); updates[id] = update; // Create a 201 response. var response = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(update.Status) }; response.Headers.Location = new Uri(Url.Link("DefaultApi", new { action = "status", id = id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
و در متد زیر باز action name چکاری انجام میده.
[HttpPost] [ActionName("Simple")] public HttpResponseMessage PostSimple([FromBody] string value) { if (value != null) { Update update = new Update() { Status = HttpUtility.HtmlEncode(value), Date = DateTime.UtcNow }; var id = Guid.NewGuid(); updates[id] = update; var response = new HttpResponseMessage(HttpStatusCode.Created) { Content = new StringContent(update.Status) }; response.Headers.Location = new Uri(Url.Link("DefaultApi", new { action = "status", id = id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); }
از نام آن مشخص است نام اکشنی که برروی آن Attribute را قرار داده اید تغییر می دهد.
<HttpPost> _ <ActionName("Complex")> _ Public Function PostComplex(update As Update) As HttpResponseMessage If ModelState.IsValid AndAlso update IsNot Nothing Then ' Convert any HTML markup in the status text. update.Status = HttpUtility.HtmlEncode(update.Status) ' Assign a new ID. Dim id = Guid.NewGuid() updates(id) = update ' Create a 201 response. Dim response = New HttpResponseMessage(HttpStatusCode.Created) With { _ Key .Content = New StringContent(update.Status) _ } response.Headers.Location = New Uri(Url.Link("DefaultApi", New With { _ Key .action = "status", _ Key .id = id _ })) Return response Else Return Request.CreateResponse(HttpStatusCode.BadRequest) End If End Function
لطفا کمی بیشتر توضیح دهید.
اکشنی که شما قرار داده اید نامش PostSimple است حال اگر آن (attribute (ActionName را حذف کنید url آن به این شکل می شود posts/PostSimple ، اگر آن را حذف نکنید این گونه می شود posts/Simple
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)