create and index views combined in 1 view -


i want able add players , upon addition in same want display them in table similar page index view offers. did combine index , create views in 1 page.

but when debugging i'm have resource cannot found error.

can 1 please correct i'm going wrong

index view:

@model ienumerable<sportsmania.player> @{ viewbag.title = "create"; }  <h2>create</h2> @using (html.beginform()) { @html.antiforgerytoken()  <div class="form-horizontal">     <h4>category</h4>     <hr />     @html.validationsummary(true)      <div class="form-group">         @html.label("player name")         <div class="col-md-10">             @html.editor("player name")          </div>     </div>     <div class="form-group">         @html.label("team")         <div class="col-md-10">             @html.dropdownlist("team", viewbag.team selectlist)          </div>     </div>     <div class="form-group">         @html.label("position")         <div class="col-md-10">             @html.editor("position")          </div>     </div>     <div class="form-group">         @html.label("email")         <div class="col-md-10">             @html.editor("email")          </div>     </div>     <div class="form-group">         @html.label("type")         <div class="col-md-10">             @html.editor("type")          </div>     </div>     <div class="form-group">         @html.label("height")         <div class="col-md-10">             @html.editor("height")          </div>     </div>      <div class="form-group">         <div class="col-md-offset-2 col-md-10">             <input type="submit" value="create" class="btn btn-default" />         </div>     </div> </div> }  @{  viewbag.title = "index"; }  <h2>index</h2>  <p> @html.actionlink("create new", "create") </p> <table class="table"> <tr>     <th>         @html.displaynamefor(model => model.playername)     </th>     <th>         @html.displaynamefor(model => model.team)     </th>     <th>         @html.displaynamefor(model => model.position)     </th>     <th>         @html.displaynamefor(model => model.email)     </th>     <th>         @html.displaynamefor(model => model.type)     </th>     <th>         @html.displaynamefor(model => model.height)     </th>     <th></th> </tr>  @foreach (var item in model) { <tr>     <td>         @html.displayfor(modelitem => item.playername)     </td>     <td>         @html.displayfor(modelitem => item.team)     </td>     <td>         @html.displayfor(modelitem => item.position)     </td>     <td>         @html.displayfor(modelitem => item.email)     </td>     <td>         @html.displayfor(modelitem => item.type)     </td>     <td>         @html.displayfor(modelitem => item.height)     </td>     <td>         @html.actionlink("edit", "edit", new { id=item.id }) |         @html.actionlink("details", "details", new { id=item.id }) |         @html.actionlink("delete", "delete", new { id=item.id })     </td> </tr> }  </table> 

playercontroller:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc;  namespace sportsmania.controllers { public class playercontroller : controller  {     sportsentities db = new sportsentities();     [httppost]     public actionresult index()     {         var data = p in db.teams                     select p.teamname;          selectlist list = new selectlist(data);         viewbag.team = list;          return view(db.players.tolist());     }     public actionresult create()     {         return view();     }     [httppost]     public actionresult create(player player)     {         if (modelstate.isvalid)         {             player newrecord = new player();             newrecord.playername = request.form["player name"];             newrecord.position = request.form["position"];             newrecord.type =request.form[ "type"];             newrecord.team =request.form[ "team"];             newrecord.email = request.form["email"];             newrecord.height = request.form["height"];             db.players.add(player);             db.savechanges();             return redirecttoaction("index");         }         return view(player);      } } } 

why doing this? because don't want every time user have add player should redirected create view, want when user finishes adding players hit button "done adding" , redirected home.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -