razor - Working with Interfaces in ASP.NET mvc4 -


i trying implement interface has getfirststudent method. idea make method available viewmodels using partial view. in way, solving problem of passing multiple viewmodels(theoretically not possible) partial view.

interface

public interface iminiview  {        string getfirststudentid(); } 

firstviewmodel:

namespace xxx.viewmodel {     public class studentsviewmodel: iminiview      {         public ienumerable<studentinfoviewmodel> studentlist { get; set; }          public string getfirststudentid()         {             return = ???????         }     } } 

i used first student on partial view as...

@model.studentsviewmodel.studentlist.elementat(0).studentid    

now access in getfirststudent method. note studentinfoviewmodel has string named studentid

does help?

namespace civicaeducation.business.ces.viewmodel {     public class studentsviewmodel: iminiview      {         public ienumerable<studentinfoviewmodel> studentlist { get; set; }          private studentinfoviewmodel firststudent          {                          {                 if (studentlist == null || studentlist.count() == 0) {                     return null;                 }                  return studentlist.firstordefault();             }         }          public string getfirststudentid()         {             return firststudent == null : string.empty ? firststudent.id;         }                      // can add more methods / properties interface         public string getfirststudentname()         {             return firststudent == null : string.empty ? firststudent.name;         }     } } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -