将数据从ASP.NET视图传递到控制器 [英] Pass data from ASP.NET view to controller
问题描述
这是观点:
This is the view :
@foreach (var module in Model)
{
if (module.Placeholder == "head")
{
Html.RenderAction(module.Control, "ContentHtml", module.Content);
}
<br />
}
这是控制器:
And this is the controller :
public ActionResult Tabelar2(string content)
{
var movies = db.ContentHtmls.Where(s => s.Content.Contains(content));
return View(movies);
}
仅当我设置内容'test1时才有效'在url中,示例localhost:58881 / Home / About / test1,我想要的是如何在此行中将module.Content字段读入数据库
This works only when i set the content 'test1' in the url , example localhost:58881/Home/About/test1 , what I want is how to read the module.Content field into database in this row
Html.RenderAction(module.Control, "ContentHtml", module.Content);
,然后将该值传递给控制器
, and then pass that value into the controller
public ActionResult Tabelar2(string content)
,因此它只显示带有该值的新闻内容。这行
, so it can show only the News with that content. This line
Html.RenderAction(module.Control, "ContentHtml", module.Content);
转到ContentHtml控制器,转到基于module.Control的特定Action,在本例中为Tabelar2,路由值应该是module.Content。
我尝试了什么:
我刚刚解释了上面的问题
goes to ContentHtml controller , to the certain Action based on module.Control , in this case Tabelar2 , and the route values should be the module.Content.
What I have tried:
I just explained the problem above
推荐答案
您需要将POST BACK数据封装在FORM中。
You need to encapsulate the POST BACK data in a FORM.
@using (Html.BeginForm()) {
<p>
<!-- Fields to post back go here -->
<input type="submit" value="Delete" /> |
</p>
}
更多信息:
* FormExtensions.BeginForm方法(HtmlHelper)(System.Web.Mvc.Html) [ ^ ]
* ASP。 NET MVC 4助手,表单和验证| Microsoft Docs [ ^ ]
* asp.net mvc - @ Html.BeginForm()如何工作? - 堆栈溢出 [ ^ ]
More info here:
* FormExtensions.BeginForm Method (HtmlHelper) (System.Web.Mvc.Html)[^]
* ASP.NET MVC 4 Helpers, Forms and Validation | Microsoft Docs[^]
* asp.net mvc - How does @Html.BeginForm() works? - Stack Overflow[^]
>
这篇关于将数据从ASP.NET视图传递到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!