Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
asp.net javascript到数据库_Asp.net_Razor - Fatal编程技术网

asp.net javascript到数据库

asp.net javascript到数据库,asp.net,razor,Asp.net,Razor,我们一直在努力解决这个问题。我想尽了一切办法。我使用javascript将数据传递给db,可以很好地处理另一个页面上的ints,但是现在使用字符串它就不起作用了:s @using (Html.BeginForm(null, null, FormMethod.Post, new{@id="manageForm"})) { @Html.AntiForgeryToken() <span class="actions"> @T(User.Id.ToSt

我们一直在努力解决这个问题。我想尽了一切办法。我使用javascript将数据传递给db,可以很好地处理另一个页面上的ints,但是现在使用字符串它就不起作用了: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>
}
数据存取

   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();
    }
public void FollowTag(int-id,string-tag)
{
DbCommand comm=GetCommand(“SPTagFollow”);
//用户id
comm.AddParameter(this.Factory,“id”,id);
//我要跟
comm.AddParameter(this.Factory,“tag”,tag);
通信安全执行查询();
}
路由设置良好,sql(存储过程)执行完美。希望你们中有人能看到一些明显的东西


干杯

我认为是打字错误的问题,请检查您最后的

//此提交按钮将完成此工作
}

应该这样做。如果您使用锚定标记只是为了设计样式,那没关系,否则您应该使用另一种方式,我认为更清晰,而且它利用了razor的强大功能。

不知道如何使用razor管理它,但通常如果我想用javascript上传到数据库,我会使用ajax。这是一个php实现,但javascript是相同的。它只是将表单值传递给服务器代码进行上传`为奥顿干杯。稍后我将使用ajax。我从来没有使用过ajax,所以我打算这样做,让一切就绪,然后再摆弄ajax。也许我现在应该看看:P干杯谢谢你,非常有帮助。希望我能给出这个答案,但代码不能正常工作,非常奇怪,因为它传递了值,然后返回到页面,但在db中什么都没有,非常令人沮丧。谢谢你:)嘿,如果你能帮忙的话,这条路线对吗?从tags/sample但实际上是tags/{tag}调用是几个小时后将标记作为约束的routewith,它最终被修复。我从论坛控制器的视图中调用用户控制器,必须将其全部转移。这不可能吗?这意味着,如果我想让用户能够跟踪标签,我就必须将整个东西添加到每个控制器中。那将是多么混乱啊。你不能从控制器外部调用此类操作(在我的案例中,这是在用户控制器内部调用操作,但从论坛调用)我的意思是用户能够从任何视图(如通过弹出窗口等)跟踪标记
[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();
    }
@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")' />
}