I have a bunch of come delimited items on my db table column.
Example
Peter, Greg, Paul, Mary,
My question is, how do I display these items as checked Items on my view?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ramesh MaruthiPosted Aug 29, 2014, 1:39 PM
ceci belaPosted Aug 29, 2014, 1:34 PM
Thank you both Ramesh & RJ!
Ramesh MaruthiPosted Aug 28, 2014, 5:31 PM
1)
return View(myString.AsEnumerable)
2)
//controller
List
return View(myString );
//view
@model List
// and property Model is type of List
@foreach(var item in Model)
{
}
Ramesh MaruthiPosted Aug 28, 2014, 5:14 PM
ceci belaPosted Aug 28, 2014, 5:10 PM
I got the error below.
The type or namespace name 'CheckListBoxItem' could not be found (are you missing a using directive or an assembly reference?)
When I tried return View(ViewBag.CheckedItems)
I got this error:
Exception Details: System.InvalidOperationException: The view 'NY NJ CA ND ' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/home/NY NJ CA ND .aspx
~/Views/home/NY NJ CA ND .ascx
~/Views/Shared/NY NJ CA ND .aspx
~/Views/Shared/NY NJ CA ND .ascx
~/Views/home/NY NJ CA ND .cshtml
~/Views/home/NY NJ CA ND .vbhtml
~/Views/Shared/NY NJ CA ND .cshtml
~/Views/Shared/NY NJ CA ND .vbhtml
ceci belaPosted Aug 28, 2014, 4:55 PM
But the controller shows there is data as shown here.
https://www.dropbox.com/s/swkvozcga0ofnwm/debug.png?dl=0
is it the way I am saving the data in ViewBag or is it the problem when I access the ViewBag?
Ramesh MaruthiPosted Aug 28, 2014, 4:41 PM
I mean what your getting if you do like this item. after item . what intelisense giving ?
ceci belaPosted Aug 28, 2014, 4:34 PM
Controller
// Response.Write("Debug:"+ViewBag.CheckedItems) <= this works.
View
NOTE: if I do a Response.Write(ViewBag.CheckedItems) on the controller I can see all the items.
Thanks guys I really appreciate it.
Ramesh MaruthiPosted Aug 27, 2014, 5:07 PM
Ramesh MaruthiPosted Aug 27, 2014, 5:06 PM
ceci belaPosted Aug 27, 2014, 4:52 PM
See image.
Now how can I get this into checkboxes on my View without the @Html.CheckBoxFor helper function?
I am thinking something like this:
@PlacesVisited
I might be wrong but I don't think the @Html.CheckBoxFor() is friendly in my case.
Thanks a bunch.
Ramesh MaruthiPosted Aug 27, 2014, 3:52 PM
List
ceci belaPosted Aug 27, 2014, 3:40 PM
Screenshot.
Ramesh MaruthiPosted Aug 27, 2014, 3:02 PM
ceci belaPosted Aug 27, 2014, 2:36 PM
I tried both suggestions (but without creating a new list) and got the same error.
LINQ to Entities does not recognize the method 'System.String[] Split(Char[])'
Ramesh MaruthiPosted Aug 26, 2014, 5:35 PM
List
as Rj said u can do in this way
var resu1 = db.Students.where(o => o.StudentID == "200312").select ( o => o.PlacesVisited.Split(',')).ToList();
R JPosted Aug 26, 2014, 5:29 PM
you can simply use Split(',');
see below is example.
var query = from o in db.Students
ceci belaPosted Aug 26, 2014, 5:14 PM
LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression.
When I tried this on my homecontroller
Any ideas how to use the Split() correctly with Linq?
Thanks
ceci belaPosted Aug 22, 2014, 4:19 PM
Ramesh MaruthiPosted Aug 21, 2014, 5:19 PM
don't know this works or not
ceci belaPosted Aug 21, 2014, 4:17 PM
Db Example.
---------------------------------------------
| Name | Last Name | PlacesVisited |
---------------------------------------------
| Jonh | Doe | NY, NJ, CA, RI, |
----------------------------------------------
| Mary | Lou | LA, CO, OR, NY |
---------------------------------------------
Ramesh MaruthiPosted Aug 21, 2014, 2:10 PM
http://stick2basic.wordpress.com/2013/03/12/checkboxlist-in-asp-net-mvc4/
http://forums.asp.net/t/1943984.aspx?How+to+use+checkbox+and+submit+the+check+values+