如何在没有模型的情况下获取控制器中的文本框值 [英] How to get the text box value in controller without model

查看:68
本文介绍了如何在没有模型的情况下获取控制器中的文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的mvc应用程序我有一个模型的剃刀视图,并且我有一个文本框如何获取控制器中文本框的值?
下面的
是我的控制器代码

public ActionResult SaveRecords()



{

string Title = Request.QueryString [title];

String connectionString =Data Source = ASPKCO-DANISH\\SQLEXPRESS1; Initial Catalog = PakeezaSodagran; Integrated Security = True;;

SqlConnection conn = new SqlConnection(connectionString);

conn.Open();

SqlCommand comm = new SqlCommand(insert into PropertyPosts(title)values(+ Request.QueryString [title],conn) ;

试试

{

comm.ExecuteNonQuery();



/ / Request.QueryString [text] = null;

}

catch(例外)

{

// MessageBox.Show(未保存);

}

终于

{

conn.Close();

}

返回查看();

}



这里是我的html razor视图

I have a simple mvc application i have a razor view with model and in that i have a text box how to get the value of textbox in controller ?
below is my controller code
public ActionResult SaveRecords()

{
string Title=Request.QueryString["title"];
String connectionString = "Data Source=ASPKCO-DANISH\\SQLEXPRESS1;Initial Catalog=PakeezaSodagran;Integrated Security=True;";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand comm = new SqlCommand("insert into PropertyPosts(title) values(" + Request.QueryString["title"], conn);
try
{
comm.ExecuteNonQuery();

// Request.QueryString["text"] = null;
}
catch (Exception)
{
// MessageBox.Show("Not Saved");
}
finally
{
conn.Close();
}
return View();
}

here is my html razor view

<pre lang="HTML">@using (Html.BeginForm("SaveRecords","Property",FormMethod.Post))
{
<div class="panel panel-default" style="width: 1200px; padding: 10px; margin: 10px">
        <!-- Tab panes -->
                <legend>Property Detail </legend>
                <div>
                    <label>
                        Property Title</label>
                   @Html.TextBox("title", null, new { @class = "form-control valid", @data_val = "true", @data_val_required = " Property Title is required" }) 
</div> 
                    
}





我尝试了什么:



我的控制器代码显示了我的尝试



What I have tried:

my controller code shows what i have tried

推荐答案

这是MVC 101类型的东西。我建议通过教程这里 [ ^ ]。
This is MVC 101 type stuff. I suggest going through the tutorials here[^].


这篇关于如何在没有模型的情况下获取控制器中的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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