خرید بک لینک

Vote count: 0

I sent data from database to view and showed them in drop-down list. After picking some item I got empty webpage instead of id of picked item along with drop-down list. I discovered that after picking, processing is not continuing in [HttpPost] part of controller.

Here is my controller:

namespace AssetServer.Controllers
{
    public class AssetsController : Controller
    {
    private readonly AssetContext _context;

    public AssetsController(AssetContext context)
    {
        _context = context;
    }

    // GET: Assets
    public async Task Index()
    {
        List AssetsTableList = new List();
        AssetsTableList = await _context.Assets.OrderBy(p => p.Ticker).ToListAsync();
        ViewBag.AssetsTableList = AssetsTableList.Select(m => new SelectListItem { Text = m.Ticker, Value = m.Id.ToString() }).ToList();
        return View();
    }

    [HttpPost]
    public async Task Index(Asset Asset)
    {
        ViewBag.SelectedValue = Asset.Id;

        List AssetsTableList = new List();
        AssetsTableList = await _context.Assets.OrderBy(p => p.Ticker).ToListAsync();
        ViewBag.AssetsTableList = AssetsTableList.Select(m => new SelectListItem { Text = m.Ticker, Value = m.Id.ToString() }).ToList();
        return View();
    }
}

}

And whole view:

@model IEnumerable
@using (Html.BeginForm("Index", "Assets", FormMethod.Post))
{
   @Html.DropDownList("Title", (List)ViewBag.AssetsTableList, new { onchange = "this.form.submit();" })
   @ViewBag.SelectedValue;
}

Debugging in Chrome show "500 Internal Server Error":

enter image description here

asked 46 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 4 ارديبهشت 1396 ساعت: 14:19

صفحه بندی