asp.net mvc 4 - EDITED - Object reference not set to an instance of an object -


mvc error view

@model enroldbrepository.models.results  @{ viewbag.title = "edit"; layout = "~/views/shared/_layout.cshtml"; }  <h2>edit</h2>  @using (html.beginform()) { @html.antiforgerytoken() @html.validationsummary(true)  <fieldset>     <legend>results</legend>      <div class="editor-label">         @html.labelfor(model => model.studentid)     </div>     <div class="editor-field">         @html.editorfor(model => model.studentid)         @html.validationmessagefor(model => model.studentid)     </div>      <div class="editor-label">         @html.labelfor(model => model.firstname)     </div>     <div class="editor-field">         @html.editorfor(model => model.firstname)         @html.validationmessagefor(model => model.firstname)     </div>      <div class="editor-label">         @html.labelfor(model => model.lastname)     </div>     <div class="editor-field">         @html.editorfor(model => model.lastname)         @html.validationmessagefor(model => model.lastname)     </div>      <div class="editor-label">         @html.labelfor(model => model.subjectid)     </div>     <div class="editor-field">         @html.editorfor(model => model.subjectid)         @html.validationmessagefor(model => model.subjectid)     </div>      <div class="editor-label">         @html.labelfor(model => model.subjectname)     </div>     <div class="editor-field">         @html.editorfor(model => model.subjectname)         @html.validationmessagefor(model => model.subjectname)     </div>      <div class="editor-label">         @html.labelfor(model => model.year)     </div>     <div class="editor-field">         @html.editorfor(model => model.year)         @html.validationmessagefor(model => model.year)     </div>      <div class="editor-label">         @html.labelfor(model => model.semester)     </div>     <div class="editor-field">         @html.editorfor(model => model.semester)         @html.validationmessagefor(model => model.semester)     </div>      <div class="editor-label">         @html.labelfor(model => model.result)     </div>     <div class="editor-field">         @html.editorfor(model => model.result)         @html.validationmessagefor(model => model.result)     </div>      <div class="editor-label">         @html.labelfor(model => model.resultletter)     </div>     <div class="editor-field">         @html.editorfor(model => model.resultletter)         @html.validationmessagefor(model => model.resultletter)     </div>      <p>         <input type="submit" value="save" />     </p>     </fieldset> }  <div> @html.actionlink("back list", "index") </div>  @section scripts { @scripts.render("~/bundles/jqueryval") } 

and controller's action

    public actionresult index(int id)     {         list<results> results = enrollmentsmodel.getallenrollments(id);         return view(results);     }     [httppost]     [validateantiforgerytoken]     public actionresult edit(results result)     {        return redirecttoaction("index",new {id=result.subjectid});     }  

and model

 public class results {      public int studentid { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public int subjectid { get; set; }     public string subjectname { get; set; }     public int year { get; set; }     public int semester { get; set; }     public double? result { get; set; }     public string resultletter { get; set; }  } 

the view calls controller's action "edit". in controller, supposed more stuff of course sake of simplicity tried access attribute of object result show exception.

any ideas?

if change action following works.. that's weird!!

 [httppost]     [validateantiforgerytoken]     public actionresult edit(int studentid, string firstname, string lastname, int       subjectid, string subjectname,int year, int semester,double? result, string resultletter)     {         results result2 = new results();         result2.studentid = studentid;         result2.firstname = firstname;         result2.lastname = lastname;         result2.subjectid = subjectid;         result2.subjectname = subjectname;         result2.year = year;         result2.semester=semester;         result2.result = result;         result2.resultletter = resultletter;          if (modelstate.isvalid)         {             enrollmentsmodel.saveoneenrollment(result2);         }          return redirecttoaction("index", new { id = subjectid });     } 


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -