Reputation: 193
I am learning MVC and am stuck at this. I was trying to create a filter for name, category, type, Min Value, Max value but when redirected to another view it only shows three parameters but without other values.
Controller (DetailController)
public ActionResult FilteredResult(string searchedLocation, string Type, string PCName, string MinValue, string MaxValue)
{
var A = searchedLocation;
var B = Type;
var C = PCName;
var D = MinValue;
var E = MaxValue;
return View();
}
View
@using (Html.BeginForm("FilteredResult", "Detail", FormMethod.Get))
{
<form>
<h4 style="color: #ed145b;">Find the right property for you</h4>
<ul class="form-style-1">
<li>
@Html.TextBox("Location", ViewBag.Location as string , new { @class = "field-long" })
</li>
<li>
@Html.DropDownList("Type", (SelectList)ViewBag.TypeList, "Select" , new { @class = "field-select" })
</li>
<li>
@Html.DropDownList("Category", (SelectList)ViewBag.CategoryList, "Select" ,new { @class = "field-select" })
</li>
<li>
<label for="amount">Price range:</label>
<input type="text" id="amount" class="field-long" readonly style="border:0; color:#ee2265; font-weight:bold;">
</li>
<li class="clearfix"> @Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", disabled = "true" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", disabled = "true" })
</li>
<li>
<div id="slider-range"></div>
</li>
<li>
<input type="submit" value="Search" class="btn-primary" />
</li>
</ul>
</form>
}
After clicking on search it shows like this. Only the data from dropdown is shown and other parameter like Minvalue and max value is not shown in the url. Location is showing
Can anyone help me on how I can successfully get data in the required field in the controller?
Upvotes: 0
Views: 150
Reputation: 1
because you are using disabled attribute true that means it fetches data from database but will not show on View so either make disabled = "false" or remove this attribute.
Upvotes: 0
Reputation: 14614
It's because your MinValue and MaxValue textboxes have disabled="true"
attribute. Disabled inputs won't be submitted
@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", disabled = "true" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", disabled = "true" })
You should remove the disabled
attribute
@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long" })
If you want to make those textboxes non editable, use readonly
attribute instead
@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", @readonly = "readonly" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", @readonly = "readonly" })
Upvotes: 2