Click here to Skip to main content
15,910,130 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey guys,am working on an online admission project in mvc3 web apllication.

i have created a class of students and use an inerface as the middle man between the web apllication and my domain to save my records perfectly.i have used a view to present the form to the users and save the record into the database.The saving aspect works perfectly.

But what i want to accomplish is surposing the student want 2 cahange some information after saving,i want the records to be overwritten and not resaved in the database.

so i want to create an overloaded version of my view to accomplish that.

I tried it and i got an error that says that it cannot perform or bind a null reference.
Then i realise the error is correct becos the record has to be saved first before the student can edit.

however i cant seem to edit find a way around editing the record. any help will be appreciated cos am stock..here is my code below.



SQL
public ViewResult Registration(int id)
    {
        Student student = studentrepository.Student.FirstOrDefault(p => p.ID == id);



        return View(student);
    }
   [HttpPost]
    public ActionResult Registration(Student student)
    {
        if (ModelState.IsValid)
        {
            studentrepository.Save(student);

        }



        return View(student);




    }
Posted

1 solution

Either have a flag that tells the controller explicitely if the entry is new or not. Or check before saving if the student already exists (you'll need one datum that is unique to a student such as registration number or SSN)
 
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