视图状态下无值显示
问题:
我无法找到一个解决方案,如果值为 0 或 null,则 txtboxMaxprice 的值将不会显示
请求:
如果输入文本框中的值为 0 或 null,我不希望 txtboxMaxprice 值显示在视图状态中。
该源代码采用简化版本制作,以便最终用户更容易理解。
// 钢之少年
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BokButik1.ViewModels.SokningppPerform2ViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
PerformSearch
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>SökResultat</h2>
<% using (Html.BeginForm("Alternativ1", "Sokning", FormMethod.Post))
{ %>
<table>
<tr>
<td>Maxprice</td>
<td><input type="text" id="txtboxMaxprice" name="txtboxMaxprice" value="<%: Model.Maxprice %>" /></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" value="Filtrera" /></td>
</tr>
</table>
<% } %>
//
// Post: /Sokning/Alternativ1
[HttpPost]
public ActionResult Alternativ1(decimal? txtBoxMaxprice)
{
var SokningppPerform2ViewModel = new SokningppPerform2ViewModel()
{
Maxprice = txtBoxMaxprice)
};
return View("PerformSearch", SokningppPerform2ViewModel);
}
Problem:
I have problem to find a solution that value of txtboxMaxprice will not display if value is 0 or null
Request:
I don't want the txtboxMaxprice value to display in view state if the value is 0 or null in the input textbox.
This source code is made in a simplified version to make more understandable for end users.
// Fullmetalboy
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BokButik1.ViewModels.SokningppPerform2ViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
PerformSearch
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>SökResultat</h2>
<% using (Html.BeginForm("Alternativ1", "Sokning", FormMethod.Post))
{ %>
<table>
<tr>
<td>Maxprice</td>
<td><input type="text" id="txtboxMaxprice" name="txtboxMaxprice" value="<%: Model.Maxprice %>" /></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" value="Filtrera" /></td>
</tr>
</table>
<% } %>
//
// Post: /Sokning/Alternativ1
[HttpPost]
public ActionResult Alternativ1(decimal? txtBoxMaxprice)
{
var SokningppPerform2ViewModel = new SokningppPerform2ViewModel()
{
Maxprice = txtBoxMaxprice)
};
return View("PerformSearch", SokningppPerform2ViewModel);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果写入文本框的值为
null
,则不会显示任何数字。这应该对您有用:
您可以在此示例中看到,如果
textBoxMaxValue
的值为null
,则不会将任何内容写入到value
属性中文本框。If the value written into the text box is
null
then it will not display any number.This should work for you:
You can see in this example that if the value of
textBoxMaxValue
isnull
then nothing is written into thevalue
attribute of the textbox.