Asp.net mvc MVC 3存在问题-从一个控制器向另一个控制器发送参数
我和一位朋友正在尝试创建一个网站,在那里,用户可以创建/编辑/删除国家,通过单击国家旁边的链接,用户可以访问该国家的Zipcode列表。我们在这方面有点失败,所以我们希望有人能帮助我们找出我们做错了什么 我们的守则如下: ISOerController.csAsp.net mvc MVC 3存在问题-从一个控制器向另一个控制器发送参数,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我和一位朋友正在尝试创建一个网站,在那里,用户可以创建/编辑/删除国家,通过单击国家旁边的链接,用户可以访问该国家的Zipcode列表。我们在这方面有点失败,所以我们希望有人能帮助我们找出我们做错了什么 我们的守则如下: ISOerController.cs 视图的Index.cshtml 视图Postdistrikter的Index.cshtml @model IEnumerable @{ ViewBag.Title=“Index”; } 后分布过度 @ActionLink(“Opr
视图的Index.cshtml
视图Postdistrikter的Index.cshtml
@model IEnumerable
@{
ViewBag.Title=“Index”;
}
后分布过度
@ActionLink(“Opret ny”,“Create”)
后期
拜纳文
阿迪斯
土地
@foreach(模型中的var项目)
{
@项目.后期
@项目.Bynavn
@项目.地址
@item.Iso_id
@ActionLink(“Rediger”,“Edit”,new{id=item.id})|
@ActionLink(“Slet”,“Delete”,new{id=item.id})
}
您应该使用RedirectToAction,而不是Redirect
public ActionResult GåTilPostdistrikter(int id)
{
return RedirectToAction( "index", "Postdistrikter", new { id = id } );
}
@model IEnumerable<SkarpSpedition.Models.ISO>
@{
ViewBag.Title = "ISO-Koder";
}
<h2>
ISO-Kode Oversigt</h2>
<p>
@Html.ActionLink("Opret ny", "Create")
</p>
<table>
<tr>
<th>
Sted
</th>
<th>
Alph2
</th>
<th>
Alph3
</th>
<th>
Numc
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.Sted
</td>
<td>
@item.Alph2
</td>
<td>
@item.Alph3
</td>
<td>
@item.Numc
</td>
<td>@Html.ActionLink("Postdistrikter", "GåTilPostdistrikter", new { id = item.ID }) |
@Html.ActionLink("Rediger", "Edit", new { id = item.ID }) |
@Html.ActionLink("Slet", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
using System;
using System.Linq;
using System.Web.Mvc;
namespace SkarpSpedition.Controllers
{
public class PostdistrikterController : Controller
{
PostdistriktDBContext db = new PostdistriktDBContext();
public ActionResult Index(int id)
{
var Postdistrikter = from p in db.Postdistrikts
where p.Iso_id == id
orderby p.Postnummer ascending
select p;
return View(Postdistrikter.ToList());
}
}
}
@model IEnumerable<SkarpSpedition.Models.Postdistrikt>
@{
ViewBag.Title = "Index";
}
<h2>
Postdistrikts oversigt</h2>
<p>
@Html.ActionLink("Opret ny", "Create")
</p>
<table>
<tr>
<th>
Postnummer
</th>
<th>
Bynavn
</th>
<th>
Adresse
</th>
<th>
Land
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.Postnummer
</td>
<td>
@item.Bynavn
</td>
<td>
@item.Adresse
</td>
<td>
@item.Iso_id
</td>
<td>
@Html.ActionLink("Rediger", "Edit", new { id = item.ID }) |
@Html.ActionLink("Slet", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
public ActionResult GåTilPostdistrikter(int id)
{
return RedirectToAction( "index", "Postdistrikter", new { id = id } );
}