Abhilash J A

Abhilash J A

  • NA
  • 2.4k
  • 582.7k

error - passing array value to viewdata MVC5

Jan 11 2017 9:06 AM
Hello everyone,
 
This is the Controller, 
  1. string[] arryvalidvalue = new string[] { "Red","Black","White" };  
  2.           List<SelectListItem> listValidValies = new List<SelectListItem>();  
  3.           foreach (var item in arryvalidvalue)  
  4.           {  
  5.               listValidValies.Add(new SelectListItem { Text = item, Value = item.ToString() });  
  6.           }  
  7.           ViewData["arryvalidvalue"] = listValidValies;  
 and view, 
  1. <tr><td>@Html.TextBox(item.AttributeName)</td><td>@Html.DropDownList("", ViewData["arryvalidvalue"] as List<SelectListItem>, "Select", new { size = item.AttributeMaxLength })</td></tr>  
 error occured: 
"
An exception of type 'System.ArgumentException' occurred in System.Web.Mvc.dll but was not handled in user code
Additional information: Value cannot be null or empty.
 
How can I solve this? 
 

Answers (6)