【发布时间】:2016-04-25 08:18:43
【问题描述】:
首先,我是网络开发的新手,所以请原谅我提出这个新手问题。
我的视图上有 4 个输入,我想在按下按钮时将它们发送到我的控制器。
<input type="text" name="title" />
<input type="text" name="description" />
<input type="text" name="link" />
<input type="date" name="date" />
这是我的 ControllerMethod:
public ActionResult AddNewsToList(string title ="a", string description = "b", string link = "c", string pubDate = "01-02-2016")
{
Models.RssWriter.createNewsItem(title, description, link, pubDate);
return View("News", NewsFeed.Models.RssReader.GetRssFeed());
}
那么任何人都可以指导我制作一个可以为我执行此操作的按钮吗?感谢阅读。
编辑
这就是它现在的实际样子:
CreateNews.cshtml
@using (Html.BeginForm("AddNewsToList"))
{
<table>
<tr>
<th>
Titel
</th>
<tr>
<td>
<input type="text" name="title" />
</td>
<tr>
<th>
Beskrivelse
</th>
<tr>
<td>
<input type="text" name="description" />
</td>
<tr>
<th>
Link
</th>
<tr>
<td>
<input type="text" name="link" />
</td>
<tr>
<th>
Udgivelsesdato
</th>
<tr>
<td>
<input type="date" name="date" />
</td>
<tr>
<td>
<br />
</td>
</table>
<input type="submit" id="AddNewsToList" name="AddNewsToList" value="Tilføj" />
}
但这似乎不起作用。
【问题讨论】:
-
我不明白为什么这篇文章值得投反对票。在这个网站上很难找到类似的问题。每个关于提交表单的问题都比较高级,比如同时有两个按钮。
-
你试过什么?你对 HTML、
-
默认值是因为它们是可选的
-
“似乎不起作用”是什么意思?
-
你的 ActionResult 用 [HttpPost] 装饰了吗?
标签: c# html asp.net-mvc-4 button