0
在我的數據連接 所以基本上我已經表查詢「的productTable」查詢中包含4行ID,名稱,數量及價格 所有我想要的是填補了這一表數據asp.net MVC 4如何將數據添加到表查詢
在Table.aspx我有這樣的:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Father.Models.ProductTable>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Table
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1>Table</h1>
<% using (Html.BeginForm()) { %>
<%: Html.AntiForgeryToken() %>
<%: Html.ValidationSummary() %>
<fieldset>
<ol>
<li>
<%: Html.LabelFor(z => z.ID) %>
<%: Html.TextBoxFor(z => z.ID) %>
</li>
<li>
<%: Html.LabelFor(z => z.Name) %>
<%: Html.TextBoxFor(z => z.Name) %>
</li>
<li>
<%: Html.LabelFor(z => z.Quantity) %>
<%: Html.TextBoxFor(z => z.Quantity) %>
</li>
<li>
<%: Html.LabelFor(z => z.Price) %>
<%: Html.TextBoxFor(z => z.Price) %>
</li>
</ol>
<input type="submit" value="Enter" />
</fieldset>
<% } %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
</asp:Content>
在我的TableModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;
namespace Father.Models
{
public class ProductTable
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int Quantity { get; set; }
[Required]
public int Price { get; set; }
}
}
在我TableController
:
public class TableController : Controller
{
public ActionResult Table()
{
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Table(ProductTable zxc)
{
if (ModelState.IsValid)
{
try
{
}
catch
{
}
}
return View(zxc);
}
}
什麼控制器裏面寫的,所以我終於可以把我的數據插入表