相关疑难解决方法(0)

复杂对象和模型绑定ASP.NET MVC

我有一个模型对象结构,Foo其中包含一个Bar带有字符串值的类.

public class Foo
{
    public Bar Bar;
}

public class Bar
{
    public string Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

以及使用这种结构的视图模型

public class HomeModel
{
    public Foo Foo;
}
Run Code Online (Sandbox Code Playgroud)

然后,我有一个表格,在Razor看起来像这样.

<body>
    <div>
        @using (Html.BeginForm("Save", "Home", FormMethod.Post))
        {
            <fieldset>
                @Html.TextBoxFor(m => m.Foo.Bar.Value)
                <input type="submit" value="Send"/>
            </fieldset>
        }

    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

在html中成为.

<form action="/Home/Save" method="post">
    <fieldset>
        <input id="Foo_Bar_Value" name="Foo.Bar.Value" type="text" value="Test">
        <input type="submit" value="Send">
    </fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)

最后控制器像这样处理post loos

[HttpPost]
public ActionResult Save(Foo foo)
{
    // Magic happends here …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc razor asp.net-mvc-5

28
推荐指数
1
解决办法
3万
查看次数

为什么只读文本框不会返回ASP.NET中的任何数据?

我已将文本框设置为只读.当用户单击它时,将显示日历,并且用户选择输入到只读文本框中的日期.

但是当我尝试将数据输入数据库时​​,它显示空值.怎么了?

asp.net textbox readonly

20
推荐指数
1
解决办法
2万
查看次数

模型绑定不起作用

我有以下POCO课程:

public class Location
    {
        public int LocationId { get; set; }
        public string Name { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string ZipCode { get; set; }
        public string Country { get; set; }
        public float? Latitude { get; set; }
        public float? Longitude { get; set; }
        public string PhoneNumber { get; set; }
        public string EmailAddress { get; …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-3

9
推荐指数
3
解决办法
2万
查看次数

禁用时 TextBoxFor 值不会传递给模型

我有一个禁用的输入字段,显示模型中的数据。

\n\n
<div class="form-group">\n                    @Html.LabelFor(model => model.first_name, "F\xc3\xb6rnamn", new\n            {\n                @for = "inputFirstname",\n                @class = "col-lg-3 control-label"\n            })\n                    <div class="col-lg-9">\n                        @Html.TextBoxFor(model => model.first_name, new\n                {\n                    @type = "text",\n                    @class = "form-control",\n                    @id = "inputFirstname",\n                    text = Html.DisplayNameFor(model => model.first_name),\n                    disabled="disabled"\n                })\n                    </div>\n                </div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我可以将此数据提交给 controlelr 方法:

\n\n

[http邮报]

\n\n
public ActionResult Index(RegistrationModel RegistrationModelViewModel)\n{}\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我添加disabled="disabled"first_name数据为空时,如果我删除它,我会得到正确的数据。

\n\n

我究竟做错了什么?

\n

c# asp.net-mvc razor

1
推荐指数
1
解决办法
3403
查看次数