asp.net mvc 4 - Add/get value from Database MVC4 C# -
i'm creating feature allows user add amount of money 'swiss bank'. balance of swiss bank stored in db
(id
and balance
) each user. i'm stuck on how display current balance of user , how add or witdraw amount of money. i'm new on c#
and mvc4
appreciated (just push in right direction awesome).
controller:
using system; using system.collections.generic; using system.data; using system.data.entity; using system.linq; using system.web; using system.web.mvc; using fivegangs.models; namespace fivegangs.controllers { public class bankcontroller : controller { private fgentities db = new fgentities(); // // get: /swissbank/ [httpget] public actionresult index() { var gangster = db.usergangster.firstordefault(g => g.userprofile.username == user.identity.name && g.health > 0); } public actionresult index() { return view(db.swissbank); } } }
model:
using system; using system.collections.generic; using system.linq; using system.web; namespace fivegangs.models { public partial class swissbank { public int id { get; set; } public string balance { get; set; } } }
view:
@using fivegangs.models @model system.data.entity.dbset<swissbank> @{ viewbag.title = "bank"; } <h2>bank</h2> <form> <fieldset> <legend>swiss bank</legend> <label>balance: @string.format("{0:c0}", @model.balance)</label> <span class="add-on">$</span> <input type="text" placeholder="amount..."> <span class="help-block">withdrawing swiss bank cost 25% of amount of cash withdrawn!</span> <button class="btn" type="button">deposit</button> <button class="btn" type="button">withdraw</button> </fieldset> </form>
step 1: create action method create.
public actionresult create() { return view(); }
step 2: add view same name
step 3: add action method receive post data , save
[httppost] public actionresult create(swissbank swisbank) { if(modelstate.isvalid) { db.swisbank.add(swisbank); db.sacechanges() } return view(); }
read documents:
it you.
Comments
Post a Comment