- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有一个 Url Action
<a href="@Url.Action("Create","Teacher", new { createAndAssign = true, teacherID = Model.AccountID })">Create new teacher & assign to account.</a>
传入两个路由值:createAndAssign 和 teacherID。
现在当我转到我的教师/创建页面时,我的 URL 是这样的:
.../Teacher/Create?createAndAssign=True&teacherID=ea817321-5633-4fdc-b388-5dba2c4a728e
这很好,我想要这个。现在,当我通过 POST 创建我的老师时,如何获取 createAndAssign 和 teacherID 值?
最佳答案
您可以在表单的隐藏变量中设置查询字符串值并在 GET 操作方法中呈现并在 POST 操作方法中接受它。
View 由您的 GET
操作呈现
@using (Html.BeginForm())
{
//Other form elements also
@Html.Hidden("teacher",@Request.QueryString["teacherID"] as string)
@Html.Hidden("createAndAssign",@Request.QueryString["createAndAssign"]
as string)
<input type="submit" />
}
现在在您的 HttpPost
操作方法中有一个 teacher
参数和 createAndAssign 参数,以便在您提交表单时可以使用它。
[HttpPost]
public ActionResult Create(string teacher,string createAndAssign)
{
//Save and Redirect
}
如果你的 View 是强类型的(这是我个人的偏好),这很容易,
public ActionResult GET(string teacherID,string createdAndAssing)
{
var yourVMObject=new YourViewModel();
yourVMObject.TeacherID=teacherID;
yourVMObject.CreateAndAssign=createdAndAssing;
return View(createdAndAssing);
}
在你的强类型 View 中,
@model YourViewModel
@using (Html.BeginForm())
{
//Other form elements also
@Html.HiddenFor(x=>x.TeacherID)
@Html.HiddenFor(x=>x.CreateAndAssign)
<input type="submit" />
}
并且在您的POST
操作中
[HttpPost]
public ActionResult Create(YourViewModel model)
{
//look for model.TeacherID
//Save and Redirect
}
关于asp.net - 将 RouteValues 读入 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12497142/
在我的 ASP.NET MVC 4 应用程序中,我可以过滤多个标签。在 HTML 中,它看起来像这样: One Two Three
我有一个 ActionLink 链接 @Ajax.ActionLink("Delete it!", "Delete", new {id = getTheID}, new AjaxOptions { C
我有一个包含以下 javascript 的部分页面: var url = '@Url.Action("Details", "Users", null)/' + userID; 除了具有 url 结构的
Request 和 RouteData.Values 中的 QueryString 有什么区别? 我们可以改用它们吗? 最佳答案 RouteValues 只有在 global.asax 中定义时才会从
我有一个名为“UserProfile”的区域。 从索引 View 中,我想从根 Controller (非区域)调用一个 Action 。 我使用了Html.ActionLink(“Index”,“H
所以我有一个 Url Action Create new teacher & assign to account. 传入两个路由值:createAndAssign 和 teacherID。 现在当我转
所以我有一个 Url Action Create new teacher & assign to account. 传入两个路由值:createAndAssign 和 teacherID。 现在当我转
将日期时间参数传递给 RedirectToAction 时 (Asp.Net MVC2)通过传递 DateTime 或传递日期:“13/4/2000” return RedirectToAct
我正在做以下工作: 1- 用户在文本框中输入一个值。 2- 然后点击编辑进入编辑 View 。 这是我的代码: 问题是我不知道如何从 textBox 中获取值并将其传递给 Actio
我有一个通用方法,它根据当前 Controller 、当前操作和当前可选参数(如果有)生成链接结构。 public static string GetLink(this HtmlHelper help
因此,如果我在第一个 Controller 中执行此操作: public class AController:Controller { public ActionR
在我的操作方法助手中使用它之前,我希望能够选择将哪些属性添加到我的对象中。所以我使用了一个 ExpandoObject 来实现这一点。 dynamic routeValues = new Expand
我有一个编码问题,我似乎无法掌握有关路线参数的问题。基本上,它要么从不 URL 编码,要么加倍 URL 编码。我只想对它进行单一编码! 这是我注册的路线: routes.MapRoute("Scan"
想象一个定义如下的对象: public class MyViewModel{ public List MyList { get; set; } } 在我看来,我有这个操作链接: @Ajax.A
HTML 助手 @Html.Pager来自 MvcPaging 2.0. 有 .Options(o => o.RouteValues(object RouteValues))它可以将 Model 返回
@{ ViewBag.Title = "About Us"; } @using (Html.BeginForm(new RouteValueDictionary { {"Action","In
我有一个疑问是: 当我使用下面的代码时: @(Html.ActionLink("Click Me", "ACTION", new {QueryName = ViewBag.QueryName})) 我
我的 View 如下所示: " %> 我的 Controller Action : public ActionResult S
假设我们有一个页面包含一些支持从数据库搜索的元素,那么在 Post Action 中我们需要找到哪些元素是事件的,并根据该创建路由值,如下所示: List SearchParameters = Get
当通过 RouteValueDicitonary或匿名对象到 @Url.Action 方法(或其任何类似物)中,有没有办法正确传递集合对象或 IEnumerable以便它生成一个与默认模型绑定(bin
我是一名优秀的程序员,十分优秀!