如何将html.editorfor()中的值传递给我的控制器

时间:2017-06-08 17:18:16

标签: asp.net-mvc razor asp.net-mvc-5

当我为编辑功能添加视图时,这是Visual Studio生成的代码

我想将视图中function getPostsFacebookInfo(){ $.ajax('https://graph.facebook.com/me/posts?access_token='+myFacebookToken,{ success : function(response){ $.each(response.data,function(index,response){ console.log(response); var react=function (){ if(response.hasOwnProperty('likes')) { $('#reactions').append(`<li class="list-group-item">Likes:${response.likes.data.length}</li>`); } else { $(' #reactions').append(`<li class="list-group-item">Likes:0</li>`); } if(response.hasOwnProperty('comments')) { $('#reactions').append(`<li class="list-group-item">Comments:${response.comments.data.length}</li>`); }else { $('#reactions').append(`<li class="list-group-item">Comments:0</li>`); } if(response.hasOwnProperty('shares')) { $('#reactions').append(`<li class="list-group-item">Shares:${response.shares.data.length}</li>`); }else { $('#reactions').append(`<li class="list-group-item">Shares:0</li>`); } }; $('#panelbody').append(` <div class="well"> <div class="row"> <div class="col-md-9"> <p>${response.message}</p> <img src="${response.picture}" class="img-thumbnail"> </div> <div class="col-md-3" id="reactions"> <script>react();</script>//function call here.. </div> </div> </div>`); //end argument list }); } });// end ajax call }// end get facebook info getBasicFacebookInfo(); getPostsFacebookInfo(); 生成的<input>内的值传递给我的控制器。

我如何访问这些值?我可以在不通过@Html.EditorFor()手动声明文本框的情况下执行此操作吗?

<input class="form-control text-box single-line" id="Surname" name="Surname" type="text">

1 个答案:

答案 0 :(得分:0)

UPDATE
找到了答案,我只需要在控制器内部的函数中将此代码作为参数传递,该控制器将创建一个具有Include内属性的对象用户
public string Submit ([Bind(Include = "Name")] User user){ }