我正在创建一个功能,允许用户向“瑞士银行”添加一定数量的钱。瑞士银行的余额存储在每个用户的db
(id
和) 中。balance
我被困在如何显示用户的当前余额以及如何添加或提取金额上。我是新手c#
,mvc4
因此非常感谢您的帮助(只要朝着正确的方向前进就很棒了)。
控制器:
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);
}
}
}
模型:
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; }
}
}
看法:
@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 from your Swiss bank will cost you 25% of the amount of cash withdrawn!</span>
<button class="btn" type="button">Deposit</button>
<button class="btn" type="button">Withdraw</button>
</fieldset>
</form>