RadioButton值需要存储在MVC中的数据库中 [英] RadioButton Value Need to Store in Database in MVC

查看:78
本文介绍了RadioButton值需要存储在MVC中的数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在工作Asp.Net MVC 2项目。



我有阅读中的RadionButton



看起来像:



O 1

O 2

O 3



当用户点击RadioButton的任何人需要将值存储在数据库中时。

示例:用户选择radiobutton1需要存储在数据库中并显示alter Message选择哪个值。我正在使用EntityDatabase Framework。



发送示例代码,我将感激你。



先谢谢。

解决方案

我没有任何代码方便发送给你,但它不应该太难。无论何时,无线电按钮的状态发生变化,都会产生一个事件。您只需要为事件提供处理程序,然后生成UPDATE查询以保存新状态。无论您实现捕获事件的任何过程都可以使用MessageBox控件为您显示消息。


我的表

表名:Infom

列名:Id(PK,int),性别(char(2)



在项目中附加数据库我使用过LINQ to SQL数据



IN CONTROLLER

InfoDataContext idc = new InfoDataContext();

public ActionResult Index()

{

返回查看();

}

[HttpPost]

公共ActionResult索引(HomeModel hm)

{

var g =None;

if(hm.Gender == true)

g =M;



else

g =F;



Infom i = new Infom() ;

i.Gend er = g;

idc.Infom.InsertOnSubmit(i);

idc.SubmitChanges();

返回View();

}

IN MODEL

公共类HomeModel

{

public bool性别{get;设置;}

}



在视图中

<%using(Html.BeginForm())

{%>

<%= Html.RadioButton(Gender,true)%>男性

<%= Html.RadioButton(性别,假)%>女性



<%}%>

Hi Friends,

I am working Asp.Net MVC 2 project.

I have RadionButton in ViewPage

Looks like:

O 1
O 2
O 3

When User Click anyone of RadioButton need to store the value in "Database".
Example: User select radiobutton "1" one need to store in database and display alter Message which value is selected. I am using EntityDatabase Framework.

Please send the Example code,I will be Thankful to you.

Thanks in Advance.

解决方案

I don't have any code handy to send you, but it shouldn't be too hard. Anytime the state of a radiobutton changes, it will generate an event. You just need to provide a handler for the event, then generate an UPDATE query to save the new state. Whatever procedure you implement to capture the event can display a message for you using a MessageBox control.


My Table
Table name: Infom
Column Name: Id(PK,int), Gender(char(2)

attach database in your projecti have used the LINQ to SQL data

IN CONTROLLER
InfoDataContext idc = new InfoDataContext();
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HomeModel hm)
{
var g = "None";
if (hm.Gender ==true)
g = "M";

else
g = "F";

Infom i = new Infom();
i.Gender = g;
idc.Infom.InsertOnSubmit(i);
idc.SubmitChanges();
return View();
}
IN MODEL
public class HomeModel
{
public bool Gender{get; set;}
}

IN VIEW
<%using (Html.BeginForm())
{ %>
<%=Html.RadioButton("Gender", true) %>Male
<%=Html.RadioButton("Gender",false) %>Female

<%} %>


这篇关于RadioButton值需要存储在MVC中的数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆