0
路由值在Post
控制器,URL是這樣的:獲取AJAX動作+ Asp.net MVC 3
http://127.0.0.1/post/5006/some-text-for-seo-friendly
{contoller}/{id}/{seo}
public ViewResult Index(){
.....
}
我在索引視圖中使用Ajax.BeginForm
並將其映射到相同的控制器AddComment
動作。
@using (Ajax.BeginForm("AddComment", "Post", new AjaxOptions()
{
HttpMethod = "GET",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "comment-container"
}))
{
<textarea cols="2" rows="2" name="comment" id="comment"></textarea>
<input type="submit" value="Add Comment" />
}
和控制器
public PartialViewResult AddComment(string comment){
// how can I get 5006 {id} here
}
我的問題是如何能得到{id} [5006]
在AddComment
行動。
注意:困難的方法是使用Request.UrlReferrer
並拆分'/'
並選擇表單數組。
據我所知,「Ajax Action」的參數被映射爲「Ajax.BeginForm」中使用的html標籤的名稱。你的意思是我應該在Ajax Form中使用一些隱藏字段並將值設置爲'5002'? – Mironline
尼古拉斯巴特勒,請你再次檢查問題。 – Mironline
@Mironline我已更新我的答案 –