Asp.net mvc 4 Get/POST中的冲突变量值

Asp.net mvc 4 Get/POST中的冲突变量值,asp.net-mvc-4,http-post,actionresult,Asp.net Mvc 4,Http Post,Actionresult,我已经创建了一个asp.NETMVC应用程序,它具有Get和Post方法,如 public ActionResult MyData(string companyid) { MyModel model= new MyModel (); model = (LINQ) ; return View(model); } [HttpPost] public ActionResult MyData(MyModel model) { if(model.companyid&

我已经创建了一个asp.NETMVC应用程序,它具有Get和Post方法,如

public ActionResult MyData(string companyid) 
{
    MyModel model= new MyModel (); 
    model = (LINQ) ;
    return View(model);
}

[HttpPost]
public ActionResult MyData(MyModel model) 
{
    if(model.companyid>0)
    { 
       //Update Database
    }
    else
    {
       // insert database
    }
    return View(model);
}


public class MyModel
{
   public int companyid {set; get;}
   public string Name {set; get;}
   public string Address {set; get;}
}
现在我的问题是:我总是在帖子中得到model.companyid=0,即@if(model.companyid>0)

当我更新get方法时 来自公共操作结果MyData(字符串companyid) 公开ActionResult MyData(字符串cid) 它起作用了


i、 e.将companyid重命名为cid,说明发生的原因。请让我知道…我想,我们有单独的get和post方法。

您可能有一个带有参数
{cid}
的路由,或者该参数在查询字符串中提供,如
foo.com/MyData?cid=123
您是否以某种方式将公司ID存储在表单视图中,例如在隐藏字段中?如果您需要控制器中的公司ID,这是必需的。请尝试为模型字段添加虚拟。我已在视图中显示隐藏字段。。。