Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working student issue book form.in that i am getting values,i have field list table in which i added multiple books of a particular student,when i am submitting it is saving only single book.In database i have create multiple columns to save book id's of each book in each column.how to solve this.
here is my controller post method

What I have tried:

[HttpPost]
public ActionResult Create(Student_Issue_Book Student_Issue_BookObj)
{
var rollNoRecord = db.Student_Issue_Book.FirstOrDefault(a => a.Delete_Flag == false && a.Issue_Return_Id == Student_Issue_BookObj.Issue_Return_Id );
if (rollNoRecord == null)
{
Student_Issue_BookObj.Last_Updated_By = CurrentUserID;
Student_Issue_BookObj.Last_Updated_Date = DateTime.Now.ToUniversalTime();
Student_Issue_BookObj.Created_By = CurrentUserID;
Student_Issue_BookObj.Creation_Date = DateTime.Now.ToUniversalTime();
// ViewBag.EMPLOYEE_ID = new SelectList(db.Student_Registration, "Registration_Id", "Student_First_Name");
if (_CRUDrepository.CreateNewObject(Student_Issue_BookObj))
{
return RedirectToAction("Index");
}
}
FillViewBag();

ModelState.AddModelError("", "This book is not there in library.");
return View();
}
Posted
Updated 9-Apr-16 21:35pm
Comments
[no name] 14-Mar-16 3:40am    
In code snippet where did you set bookids for a student?
Hussain Javed 14-Mar-16 4:33am    
by using this code i am able to store only one book id in database,how to save multiple book id's in database.

1 solution

For posting multiple or list of books your Model should hold list.

What i mean is use collections for Model

e.g.
C#
public class Book
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }


    public class BookViewModel
    {
        List<Book> Books { get; set; }
    }


i.e your model =BookViewModel
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900