获取控制器中的选中值 [英] Get the checked value in the controller
本文介绍了获取控制器中的选中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的HTML代码:
使用(Html.BeginForm(SuccessFacebookPost,JobOffer))
{
< div 类 = hiddenF >
< ul id = childCheckBox >
< a id = page href = # < span class =code-keyword>> < input id = OnPage type = 复选框 class = childCheckBox 名称 = BoxChecked value = OnPage / > @ ApplicationResources.PostOnPage < / a >
< a id = mur href = # > < 输入 id = OnWall type = 复选框 class = < span class =code-keyword> childCheckBox name = BoxChecked 值 = OnWall / > @ ApplicationResources.PostOnWall < / a >
< / ul >
< / div >
}
这是我的控制器代码:
public ActionResult SuccessFacebookPost( string [] BoxChecked)
{
var ids =(IEnumerable< int>)会话[ ids] ;
foreach ( var id in ids)
{
var fbConfig = manager.SocialNetworkConfigManager.GetSocialNetworkConfigByName( Facebook);
var credentials = new FacebookCredentials
{
ApiKey = fbConfig。 ApiKey,
ApiSecret = fbConfig.ApiSecret,
CallbackUrl = fbConfig.CallbackUrl,
AccountId = fbConfig.AccountId
};
FacebookEngine FBEngine = new FacebookEngine(凭据);
var joboffer = manager.JobOffer.GetJobOfferById(id);
if (BoxChecked [ 0 ] == OnPage)
{
FBEngine.PostJob(joboffer);
}
如果(BoxChecked [ 1 ] == OnWall)
{
FBEngine.PostJobOnWall(joboffer);
}
}
}
BoxChecked始终为空,我不明白错误在哪里。
所有我想要的只是测试复选框的值并执行相应的函数。
任何帮助请
解决方案
< blockquote> 如何从javascript代码中获取价值将其传递给C#代码进行测试 [ ^ ]
This my html code :
using (Html.BeginForm("SuccessFacebookPost", "JobOffer"))
{
<div class="hiddenF">
<ul id="childCheckBox">
<a id ="page" href="#"><input id="OnPage" type="checkbox" class="childCheckBox" name="BoxChecked" value="OnPage" />@ApplicationResources.PostOnPage</a>
<a id ="mur" href="#"><input id="OnWall" type="checkbox" class="childCheckBox" name="BoxChecked" value="OnWall" />@ApplicationResources.PostOnWall</a>
</ul>
</div>
}
This is my controller code :
public ActionResult SuccessFacebookPost(string[] BoxChecked)
{
var ids = (IEnumerable<int>)Session["ids"];
foreach (var id in ids)
{
var fbConfig = manager.SocialNetworkConfigManager.GetSocialNetworkConfigByName("Facebook");
var credentials = new FacebookCredentials
{
ApiKey = fbConfig.ApiKey,
ApiSecret = fbConfig.ApiSecret,
CallbackUrl = fbConfig.CallbackUrl,
AccountId = fbConfig.AccountId
};
FacebookEngine FBEngine = new FacebookEngine(credentials);
var joboffer = manager.JobOffer.GetJobOfferById(id);
if (BoxChecked[0] == "OnPage")
{
FBEngine.PostJob(joboffer);
}
if (BoxChecked[1] == "OnWall")
{
FBEngine.PostJobOnWall(joboffer);
}
}
}
BoxChecked is always null , I don't understand where is exactely the error .
All what I want is just to test the value of the checked box and execute the corresponding function .
Any help please
解决方案
How to get value from javascript code and pass it to C# code to test it[^]
这篇关于获取控制器中的选中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文