English 中文(简体)
ASP. NET MVC 3 RAZOR : 如何使用POST,就会产生“无法找到资源”错误。
原标题:ASP.NET MVC 3 RAZOR : How to use POST, it gives error "Resource can not found"

以下是管制者和观点。 当[提交]纽扣申请时,“无法找到资源”就会产生错误。 我知道使用“Get and Post”是MVC的根本概念。 如果有的话,在使用“Get and Post and WHAT IS FRAONG FOLLOWING CODES时,我会清楚地看到这一概念。

Controller:

namespace MVCModelBinding.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost, ActionName("Index")] 
        public ActionResult IndexPost()
        {
            if (Request.Form.Count > 0)
            {

                string id = Request.Form["ID"];

                string fname = Request.Form["FirstName"];

                string lname = Request.Form["LastName"];

                ViewBag.StatusMessage = "Employee data received successfully for ID " + id + "!";

            }

            return View();
        }
        public ActionResult About()
        {
            return View();
        }
    }
}

view (index.chtml)

@using (Html.BeginForm("IndexPost", "HomeController",FormMethod.Post))
{
    <table>
        <tr>
            <td>
                Employee ID
            </td>
            <td>
                @Html.TextBox("ID")
            </td>
        </tr>
        <tr>
            <td>
                First name
            </td>
            <td>
                @Html.TextBox("FirstName")
            </td>
        </tr>
        <tr>
            <td>
                Last Name
            </td>
            <td>
                @Html.TextBox("LastName")
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Submit" />
            </td>
        </tr>
    </table>
}

成就

Paul

最佳回答

表格中使用的行动名称和管制名称是错误的。 应当:

@using (Html.BeginForm("Index", "Home", FormMethod.Post))

行动名称只是Index",因为你在ActionNameAttribute上指明了该名称。 控制者的名称不应包括“主计长”的颜色。

问题回答

暂无回答




相关问题
PHP - Dealing with GET and POST arrays

In my webapp I have a page called display.php. The script in this page behaves in different ways depending on POST and GET array content/existence, let s say: If I call this page and GET array isset, ...

PHP GET question - calling from a POST call

I have a quick question i hope you guys can answer, i ve got a search system that uses POST to do searches, now i want to track queries using Google Analytics but it requires using GET url parameters ...

Can t use Get in CodeIgniter

So I m using codeigniter and I ve had very letter experience with it so far but here s my issue. I have an if statement I ve set up that says if (@$_GET[ f ] == callback ) then do something, if not, ...

Not using $_GET parameters

In working with CodeIgniter, it appears $_GET is disabled by default. I m wondering why this is. A lot of times, I want to build very long search queries. So for example, I have a form that allows ...

Get Text UIWebView PHP script

Basically my app has a UIwebView which loads a php script with input of user data. The script then uses printf(some info). This all works and it prints it right the UIWebView. Basically what I want to ...

Jquery Ajax or Get doesn t work on SOME IE

<script type="text/javascript"> $(document).ready(function(){ function listadepoimentos(page){ // $.get("ajaxes.php", {act: listadepoimentos , page:page}, ...

热门标签