これに苦労してきました。私が考えることができるすべてを試しました。私はJavaScriptを使用してデータをdbに渡しますが、別のページのintでは正常に動作しますが、文字列では機能しません:s
@using (Html.BeginForm(null, null, FormMethod.Post, new{@id="manageForm"}))
{
@Html.AntiForgeryToken()
<span class="actions">
@T(User.Id.ToString()) @T(" ") @T(ViewData["Tag"].ToString())
<input type="hidden" name="tag" value="fr" />
<input type="hidden" name="id" value="3" />
<a href="#"class="bttn green large" onclick="return following.();">@T("Follow")</a>
</span>
}
Javascript
<script type="text/javascript">
function followTag() {
$('#manageForm').attr('action', '@(Url.Action("FollowTag"))').submit();
return false;
}
</script>
コントローラ
[RequireAuthorization]
[HttpPost]
public ActionResult FollowTag(int id, string tag)
{
_service.FollowTag(id, tag);
return RedirectToAction("TagPage","Detail", new
{
});
}
データアクセス
public void FollowTag(int id, string tag)
{
DbCommand comm = GetCommand("SPTagFollow");
//user id
comm.AddParameter<int>(this.Factory, "id", id);
//id to follow
comm.AddParameter<string>(this.Factory, "tag", tag);
comm.SafeExecuteNonQuery();
}
ルートは正常にセットアップされ、sql(ストアド プロシージャ) は完全に実行されます。うまくいけば、あなたの一人が何か明らかなことを見ることができます
乾杯