0

これに苦労してきました。私が考えることができるすべてを試しました。私は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(ストアド プロシージャ) は完全に実行されます。うまくいけば、あなたの一人が何か明らかなことを見ることができます

乾杯

4

1 に答える 1

0

タイプミスの問題だと思います。最後の<a>タグを確認following.()し、onclickイベントに入力しました。javascript関数が呼び出されていることを確認してくださいfollowTag

それでも問題が解決しない場合は、そのfoolowTag関数を削除します。次のように、フォーム自体でアクションとコントローラーを指定できます。

@using (Html.BeginForm("FollowTag", "YourControllerName", FormMethod.Post)) {
    ...
    //Delete this line
    //<a href="#"class="bttn green large"  onclick="return following.();">@T("Follow")</a>
    //This submit button will do the job
    <input type='submit' value='@T("Follow")' />
}

それはそれをする必要があります。スタイリングのためだけにアンカータグを使用している場合は、それ以外の場合は別の方法で使用する必要があります。より明確であり、かみそりの優れた機能を利用していると思います。

于 2013-03-11T05:04:48.313 に答える