TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Faruk Shaikh
NA
13
989
Html Dropdownlist helper binding issue after post request
Jun 5 2015 1:19 AM
Hi Friends ,
I am stuck into the situation known as
(Index was out of range. Must be non-negative and less than the size of the collection.) for Html Dropdownlist
This Exception raises when i post a request in asp.net mvc to an action method it keeps on giving me above error
View
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Models.Prices>
@Html.DropDownList("Id", new SelectList((List<SelectListItem>)ViewBag.Id, "Value", "Text"), "Select")
Controller
[Authorize]
[HttpPost]
public ActionResult Base(Prices prices, int? page)
{
prices.commodity = ListCommodities(2);
ViewBag.Id = prices.commodity;
List<Prices > lstPrices = new List<Prices >();
lstPrices
= ListPrices (prices.marketid, prices.Id,prices.exchangeid, 0, prices.fromdate, prices.todate);
var lstPrices1 = lstPrices.ToPagedList(page ?? 1, 10);
return View(lstPrices);
}
//Method to get Commodities
public List<SelectListItem> ListCommodities(int id)
{
Prices prices = new Prices();
List<SelectListItem> lstCommodities = new List<SelectListItem>();
DataTable dt = DAL.PricesDAL.ListCommodities(id);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
lstCommodities.Add(new SelectListItem() { Value = dr["Id"].ToString(), Text = dr["Product"].ToString() });
}
}
}
return lstCommodities;
}
Reply
Answers (
2
)
get hidden field value in mvc controller
Difference bw ref and out key word in c#