Full width home advertisement

Post Page Advertisement [Top]

If you use Kendo UI MVC helpers, then you should name your widget exactly as parameters names in your controller's actions.

For example, we create some upload widget:

<div>
@(Html.Kendo().Upload() .Name("attachments") .Async(async => async .Save("Save", "Home") .AutoUpload(true) ) )
</div>

As you can see, we name upload widget as "attachments". Now, we create Save action in our Home controller.

public ActionResult Save(IEnumerable<HttpPostedFileBase> files) { foreach (var file in files) { var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName); file.SaveAs(destinationPath); } return Content(""); }

If you set breakpoint into Save action, you can see, that "files" parameter is null. To fix that issue, we rename "files" parameter as name of out upload widget, i.e. "attachments":

public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments) { foreach (var file in attachments) { var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName); file.SaveAs(destinationPath); } return Content(""); }

And that will work as you expect! Attachments are not null!

Комментариев нет:

Отправить комментарий

Bottom Ad [Post Page]

| Дизайн Colorlib