我想从剃须刀页面向控制器发送一个ID,并获取有关该ID的信息并进行编辑,但出现错误。
我使用Ado.net技术。
这是我的创业公司
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Session;
namespace WebApplication7
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDistributedMemoryCache();
services.AddSession();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
这是我的剃刀视图:
在此页面上,我想发送customer_id进行“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。 在此页面上,我想将customer_id发送到“编辑”操作。
@model IEnumerable<WebApplication7.Models.Register>
@{
ViewData["Title"] = "reglis";
}
<h2>reglis</h2>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th hidden>
@Html.DisplayNameFor(model => model.customer_id)
</th>
<th>
@Html.DisplayNameFor(model => model.customer_fname)
</th>
<th>
@Html.DisplayNameFor(model => model.customer_lname)
</th>
<th>
@Html.DisplayNameFor(model => model.customer_NationalCode)
</th>
<th>
@Html.DisplayNameFor(model => model.user_name)
</th>
<th>
@Html.DisplayNameFor(model => model.password)
</th>
<th hidden>
@Html.DisplayNameFor(model => model.Confirmpassword)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Gender)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td hidden>
@Html.DisplayFor(modelItem => item.customer_id)
</td>
<td>
@Html.DisplayFor(modelItem => item.customer_fname)
</td>
<td>
@Html.DisplayFor(modelItem => item.customer_lname)
</td>
<td>
@Html.DisplayFor(modelItem => item.customer_NationalCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.user_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.password)
</td>
<td hidden>
@Html.DisplayFor(modelItem => item.Confirmpassword)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Gender)
</td>
<td>
@*@Html.ActionLink("Edit", "Edit", new { id=item.customer_id })*@ @*|
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })*@
@*<a asp-controller="RegisterController1" asp-action="Edit" asp-route-id="@item.customer_id">Edit</a>*@
<a href="/RegisterController1/Edit/id=@item.customer_id">Edit</a>
</td>
</tr>
}
</tbody>
</table>
这是我的动作
public IActionResult Edit(int? customer_id)
{
if (customer_id == null)
{
return NotFound();
}
Register Rg = new Register();
Rg = RgEdit.GetRegisterByID(customer_id);
if (Rg == null)
{
return NotFound();
}
return View(Rg);
}
[HttpPost]
public IActionResult Edit(int? customer_id , [Bind] Register Reg)
{
if(customer_id == null)
{
return NotFound();
}
if(ModelState.IsValid)
{
RgEdit.GetRegister(Reg);
return RedirectToAction("reglis");
}
return View();
}
欢迎任何回应。