How To Accept a File POST

I’m surprised that a lot of you seem to want to save files on the server. Solution to keep everything in memory is as follows: [HttpPost(“api/upload”)] public async Task<IHttpActionResult> Upload() { if (!Request.Content.IsMimeMultipartContent()) throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); foreach (var file in provider.Contents) { var filename = file.Headers.ContentDisposition.FileName.Trim(‘\”‘); var buffer … Read more

How to pass json POST data to Web API method as an object?

EDIT : 31/10/2017 The same code/approach will work for Asp.Net Core 2.0 as well. The major difference is, In asp.net core, both web api controllers and Mvc controllers are merged together to single controller model. So your return type might be IActionResult or one of it’s implementation (Ex :OkObjectResult) Use contentType:”application/json” You need to use … Read more

Can the ViewBag name be the same as the Model property name in a DropDownList?

You should not use the same name for the model property and the ViewBag property (and ideally you should not be using ViewBag at all, but rather a view model with a IEnumerable<SelectListItem> property). When using @Html.DropDownListFor(m => m.CustomerId, ….) the first “Please Select” option will always be selected even if the value of the … Read more

Submit same Partial View called multiple times data to controller?

Your problem is that the partial renders html based on a single AdminProductDetailModel object, yet you are trying to post back a collection. When you dynamically add a new object you continue to add duplicate controls that look like <input name=”productTotalQuantity” ..> (this is also creating invalid html because of the duplicate id attributes) where … Read more

Two type of Login – One System Integrate (MVC)

Have different roles for each user type. Also have two different master page, one for administration one for users. All your administration related modules must use administration master page (this will have all administration related menus) and general user module must use user master page. After login according to their role type redirect to respective … Read more

How to get the value of @DropDownListFor in [HttpPost] at controller [duplicate]

I got the Solution for above issue. Model(MotorInput.cs) public int CatID { get; set; } Controller(UserController.cs) //To load in View page setting to viewBag from database public ActionResult Motors() { this.ViewBag.CatID = new SelectList(this.db1.motors, “id”, “cat”); return View(); } View(Motors.cshtml) @model BLL.Models.MotorInput @{ ViewBag.Title = “Motors”; Layout = “~/Views/Shared/_UserLayout.cshtml”; } @using (Html.BeginForm()) { @Html.DropDownList(“CatID”, (SelectList)ViewData[“CatID”], … Read more