如何将文本框值传递给Windows窗体中的模型,MVC-C# [英] how to pass the textbox value to model in windows form,MVC-C#

查看:133
本文介绍了如何将文本框值传递给Windows窗体中的模型,MVC-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将对我进一步推进项目提供很大的帮助.

我需要检查数据库的文本框值(窗体).如果存在,则尝试显示警告消息,如果不存在,则要求用户输入值.

我尝试以Windows形式的MVC格式实现此代码.

您可以为此提供示例代码吗?有什么建议吗?


谢谢.

This will be a great help for me to carry my project further.

I need to check the text box value(form) with database. If it exist I try to show warning message and if not ask the user to enter the values.

I try to implement this code with Windows form,MVC format.

Can you give sample code for this? Any suggestion ideas?


Thank You.

推荐答案

一个小建议.您可以做的一件事是,集中注意力从文本框中使用其ID检索值,例如
A small suggestion. One thing you can do is, On focus out from the textbox retrieve the value using its id like


(#textboxId").val();
如果使用的是MVC,则基于该值对控制器操作进行ajax调用,在该操作中将检查文本框值是否存在或与数据库中的数据匹配.如果存在,则返回true,否则返回false,然后警告用户需要添加值.这是可以通过.NET中的MVC来实现的.
回传您的查询(如果有的话).
谢谢
:)
("#textboxId").val();
based on that value make an ajax call to the controller action if you are using MVC, where you would check if the textbox value exists or matches with the data from the database. If exists return true else if false then alert that the user needs to add the values. This is what can be achieved through MVC in .NET.
Post back your queries if any.
Thanks
:)


视图:
私人void textBox1_KeyDown(object sender,KeyEventArgs e)
{
如果(e.KeyCode == Keys.Enter)
{

//textBox1.Text = controller.CheckAndGetBarcode();
MessageBox.Show(controller.CheckAndGetBarcode());

}
}
型号:

公共类ProductModel
{
//公共字符串s;


/*公共字符串GetBarcode()
{


label_nameDataContext ptable =新的label_nameDataContext();
var pr =来自ptable中的产品p.其中p.Gtin =="8"的产品选择p;
foreach(pr中的变量项)
{
s = item.ProductCost.ToString();
}
return s;
}


}

控制器
公共字符串CheckAndGetBarcode()
{
字符串returnvalue =";
如果(CheckAvailability())
{

ProductModel模型= new ProductModel();
returnvalue = model.GetBarcode();
}
返回returnvalue;
}

公共布尔CheckAvailability()
{
返回true;
}

在模型中,我手动给出了8 ...我想要做的是8的实例,我想获取textbox1的值.

你能帮我吗?
View:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{

//textBox1.Text = controller.CheckAndGetBarcode();
MessageBox.Show(controller.CheckAndGetBarcode());

}
}
Model:

public class ProductModel
{
//public string s;


/*public string GetBarcode()
{


label_nameDataContext ptable = new label_nameDataContext();
var pr = from Product p in ptable.Products where p.Gtin == "8" select p;
foreach (var item in pr)
{
s = item.ProductCost.ToString();
}
return s;
}


}

Controller
public string CheckAndGetBarcode()
{
string returnvalue = "";
if (CheckAvailability())
{

ProductModel model = new ProductModel();
returnvalue = model.GetBarcode();
}
return returnvalue;
}

public bool CheckAvailability()
{
return true;
}

In model i gave 8 by manually...What i want to do is instance of 8 i want to get the value of textbox1.

Can u help me?


这篇关于如何将文本框值传递给Windows窗体中的模型,MVC-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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