C# mvc将输入值传递给控制器参数

C# mvc将输入值传递给控制器参数,c#,html,asp.net-mvc-4,button,C#,Html,Asp.net Mvc 4,Button,首先,我是网络开发新手,所以请原谅我这个新手问题 我的视图上有4个输入,当按下按钮时,我想将其发送到控制器 <input type="text" name="title" /> <input type="text" name="description" /> <input type="text" name="link" /> <input type="date" name="date" /> 那么,有谁能指导我制作一个能为我做到这一点的按钮吗?谢

首先,我是网络开发新手,所以请原谅我这个新手问题

我的视图上有4个输入,当按下按钮时,我想将其发送到控制器

<input type="text" name="title" />
<input type="text" name="description" />
<input type="text" name="link" />
<input type="date" name="date" />
那么,有谁能指导我制作一个能为我做到这一点的按钮吗?谢谢你的阅读

编辑

这就是现在的实际情况:

CreateNews.cshtml

@使用(Html.BeginForm(“AddNewsToList”))
{
滴度
涂鸦
链接
Udgivelssdato

}

但是这似乎不起作用。

您可能需要将控制器名称指定为
BeginForm
方法的第二个参数

正如@Gendolkari还指出的:“如果您提供操作名称,那么您还必须提供控制器名称。否则,该参数将被解释为RouteValues对象。他可能只使用BeginForm(),而不使用任何参数。”

比较:

  • BeginForm(字符串、对象)
  • BeginForm(字符串,字符串)

我不明白这篇文章为什么值得投反对票。在这个网站上很难找到类似的问题。关于提交表单的每个问题都更高级,比如同时有两个按钮。您尝试过什么?你知道HTML吗,tag?还有,为什么要为操作定义默认参数值?默认值是因为它们是可选的“似乎不起作用”是什么意思?是否用[HttpPost]修饰操作结果?
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());
    }
@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" />

}