ASP .NET MVC html.textbox没有返回值 [英] ASP .NET MVC html.textbox not returning value

查看:180
本文介绍了ASP .NET MVC html.textbox没有返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器:

    [HttpPost]
    public ActionResult Edit(FormCollection form)
    {

        string name = form["firstname"];
    }

查看:

@Html.TextBox("firstname", null, new { style = "width:100px" })

我输入一些文本到文本框,并提交表单,但是当我在字符串声明中断程序,名称变量是空的,即使当我将鼠标悬停在表格[名字],我在输入的值文本框出现在Visual Studio中。

I am entering some text into the textbox and submitting the form but when I break the program at the string declaration, the name variable is empty, even though when I hover over form["firstname"], the value I entered in the textbox appears in Visual Studio.

如何可以在文本框中输入的文本,并将其放置到一个字符串变量?

How can take the text entered in the textbox and place it into a string variable?

推荐答案

很可能是因为该变量没有在code的任何地方使用以后您遇到这种情况。如果它看到变量没有以后使用,它是足够聪明,不要去在意它分配一个值。

most likely this happens to you because this variable is not used anywhere in the code later on. If it sees that the variable is not used later, is it smart enough not to care about assigning a value to it.

要看看它是否工作后,你只需添加这code:

to see if it works simply add this code after yours:

string s = name;

这篇关于ASP .NET MVC html.textbox没有返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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