Asp.net mvc ASP.NET MVC表单处理问题

Asp.net mvc ASP.NET MVC表单处理问题,asp.net-mvc,Asp.net Mvc,我的控制器中有以下操作: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, FormCollection formCollection) { // do stuff with form collection } 这个很好用。我的问题是,当我使用视图模型对象(比如MyFormViewModel)时,没有任何属性包含任何表单详细信息。e、 有一个叫做MyName的属性 在我的

我的控制器中有以下操作:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(int id, FormCollection formCollection)
    {
        // do stuff with form collection
    }
这个很好用。我的问题是,当我使用视图模型对象(比如MyFormViewModel)时,没有任何属性包含任何表单详细信息。e、 有一个叫做MyName的属性

在我的表单中,有一个名为“MyName”的文本输入字段

上面的formCollection对象包含具有正确值的MyName条目

但如果我将上述代码更改为:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(int id, String MyName)
    {

    }
那么我的名字是空的

有人知道为什么会这样吗

编辑:aspx文件是:

<form action="/mycontroller/edit" method="post" id="myControllerForm" enctype="multipart/form-data">
<fieldset>
<div class="forms">
    <div class="row">
        <label> Name: </label>
        <span class="input_wrapper">
            <%= Html.TextBox("MyName", Model.MyName, new { @class = "text" }) %>
         </span>
    </div>
    <div class="row">
       <input name="" type="submit" />
    </div>
</div>
</fieldset>
</form>

姓名:

使用POST数据更新模型时是否遇到问题? 如果是这样,并且表单中的字段与实际数据模型中的字段名称相同,则只需执行以下操作:

// POST: /Room/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection)
{
    // load the actual data model from the DB using whatever ORM you use...
    MyDataModel model = dataRepository.GetItem(m => m.id == id);

    try
    {
        UpdateModel(model);
        return View(new MyViewModel(model));
    }
    catch
    {
        // error handling...
        return View();
    }
}

UpdateModel(to);方法调用将使用来自控制器当前值提供程序的数据更新提供的对象。

使用POST数据更新模型时遇到问题吗? 如果是这样,并且表单中的字段与实际数据模型中的字段名称相同,则只需执行以下操作:

// POST: /Room/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection)
{
    // load the actual data model from the DB using whatever ORM you use...
    MyDataModel model = dataRepository.GetItem(m => m.id == id);

    try
    {
        UpdateModel(model);
        return View(new MyViewModel(model));
    }
    catch
    {
        // error handling...
        return View();
    }
}

UpdateModel(to);方法调用将使用来自控制器当前值提供程序的数据更新提供的对象。

是否可以发布FormCollection类的代码并发布aspx文件。这似乎有点奇怪,sting值为null。上面添加了aspx文件-基于您发布的代码,对格式表示歉意。这确实有效。。。您是否能够解决此问题?是否能够发布FormCollection类的代码并发布aspx文件。这似乎有点奇怪,sting值为null。上面添加了aspx文件-基于您发布的代码,对格式表示歉意。这确实有效。。。你能解决这个问题吗?不幸的是,这也不起作用。即使在调用UpdateModel(model)之后,模型的属性仍然为空。不幸的是,这也不起作用。即使在调用UpdateModel(model)之后,模型的属性仍然为空