如何在没有模型的情况下获取控制器中的文本框值
我有一个简单的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