ASP.NET
- 2 ответа
- 0 вопросов
1
Вклад в тег
[HttpPost]
public ActionResult UploadForm(string ProductName, string Code, string Url)
{
var files = HttpContext.Request.Files;
StreamReader stream = new StreamReader(files[0].InputStream);
var fileToAdd = default(byte[]);
using (var memstream = new MemoryStream())
{
stream.BaseStream.CopyTo(memstream);
fileToAdd = memstream.ToArray();
}
// функция добавления записи в бд:
AddData(ProductName, Code, Url, fileToAdd);
return null;
}
public class NewsViewModel{
public IEnumerabe<NewsEntity> News{get;set;}
public SliderEntity Slider{get;set;}
}
public ActionResult Index(){
var model = new NewsViewModel(){
News=_repo.NewsEntities.Where(...).AsIEnbumerable(),
Slider=_slider.Slider.Single(...)
};
return View(model);
}
@model NewsViewModel
Слайдер
@Model.Slider
Новости
@foreach(var item in Model.News){
....
}