Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms MVC4从视图到控制器的传递模型_Forms_Asp.net Mvc 4_Post_View_Model - Fatal编程技术网

Forms MVC4从视图到控制器的传递模型

Forms MVC4从视图到控制器的传递模型,forms,asp.net-mvc-4,post,view,model,Forms,Asp.net Mvc 4,Post,View,Model,基本模型 //Model public class Car { string name{get;set;} double speed {get;set;} //etc. } 所以我打电话给外面的服务,以获得更多的数据为汽车 下面是我真的很困惑的表格。我只想用HTML写这个 但我想从这里得到一个基本的空模型。。填充它,然后发送到控制器以获取更多数据 //Controller public ActionResult ModifyCar(Car c) { c = GetAd

基本模型

//Model
public class Car
{
   string name{get;set;}
   double speed {get;set;}
   //etc.
}
所以我打电话给外面的服务,以获得更多的数据为汽车

下面是我真的很困惑的表格。我只想用HTML写这个

但我想从这里得到一个基本的空模型。。填充它,然后发送到控制器以获取更多数据

//Controller
public ActionResult ModifyCar(Car c)
{
    c = GetAdditionalData(c.name, c.speed);
    return View(c);
}
//查看
@模型车
//猜测
//以某种方式绑定@model.name
//以某种方式绑定@model.speed
//以某种方式将模型发送给控制器
对不起,我不太擅长观赏部分,但我希望你能看到我要去的地方

另外,我正在进行需要表单id的验证。。我注意到在使用HTML帮助程序生成表单时没有表单id。这将打破我写的CSS

任何帮助都将不胜感激

谢谢

试试这个:

//View
@model Car
<form id="carform" method="post" action="/Car/ModifyCar"> //Guessing
    <input id="carName"  /> //Somehow bind with @model.name
    <input id="carSpeed" /> //Somehow bind with @model.speed
    <input type="submit" /> //Somehow send the model to the controller
</form>
上述BeginForm()将呈现与以下内容相同的html:

@using(Html.BeginForm("ModifyCar","Car",FormMethod.Post,new{ id="carform" }))


但是这个“”正确吗?那只是胡乱猜测。。我看不出模型在哪里被传递回去好吧,我现在只是测试一下+1的身份证提示无效。我无法绑定到值=“@model.name”有效。。我真不敢相信事情会这么简单。它已经起作用了。您只需命名与模型匹配的属性。是的…很高兴看到它对您有效…@Proximo
@using(Html.BeginForm("ModifyCar","Car",FormMethod.Post,new{ id="carform" }))
<form id="carform" method="post" action="/Car/ModifyCar">