Html.DropDownList extensions - asp.net-mvc-4

I have a drop down list in a view bind to a model (MVC4)
#Html.DropDownList("ID_ROLE", String.Empty)
ID_ROLE is one of the property of the model
and ID_ROLE is also the name of the viewbag I pass to the view in this way
ViewBag.ID_ROLE = new SelectList(lista_ruoli.OrderBy(x => x.DESCR_ROLE), "ID_ROLE", "DESCR_ROLE", user_to_edit.ID_ROLE);
In this way it works..
but I don't understand why I can't find an extension of the HtmlHelper.DropDownList
which fits with
#Html.DropDownList("ID_ROLE", String.Empty)
Is this way wrong or not?
Thank you!

Not sure if I understand correctly, but if you want the list to show up in the dropdown, you need to provide the list to the HTML helper:
#Html.DropDownList("ID_ROLE", (SelectList)ViewBag.ID_ROLE)

Related

Make Text Field item as Read Only in APEX 5.0

I have some text field page items on my APEX 5.0 page and I want to make the textboxes as read only/non-editable. During the page load I want to use these text boxes for only the data display on the page and should be non-editable.
Can somebody advice on how to do that? What attributes need to set for this?
This answer is a bit late to the party, but I found myself confronted to this problem and I wanted to share the solution I came up with.
In fact you just need to create your item as a text area, let say P1_Text_Area and you give it a readonly attribute using JavaScript. Write thoses 2 lines in the "Function and Global Variable Declaration" of your page:
var disItem = document.getElementById('P1_Text_Area');
disItem.readOnly = true;
Hope this helps someone in need.
in item properties find the
Read Only group
and set Read Only Condition Type as Always
or the option that suits to you
You can use disabled + save session state ==> read only

Passing data from a controller to a view (MVC)

I am having a small issue where I cannot pass the data to the view.
In the controller I have
ViewBag.InvalidParts = Invalid;
In the view I have
<h2>#Html.DisplayText("InvalidParts")</h2>
I get this error on my web page:
System.Collections.Generic.List`1[System.String]
When I step through my code I do see that my view bag has 20 records stored in it, my problems is that I cannot view them. Am I making a wrong call? Thanks in advance for the help
in your foreach you need to use the variable that you have defined. In this situation I don't think you need the helper. Try changing your code to
#foreach(var invalid in ViewBag.InvalidParts){
<text>
<h2>#invalid</h2>
</text>
}

model data not binding to dropdownlist mvc 4

I have a single razor view in which i am trying to implement both Create and Edit options. Here is cshtml code for a drop down field:
#Html.DropDownListFor(model => model.StateID, (SelectList)ViewBag.StateID, "--Select--", new { #Id = "ddlState" })
However in edit mode although all the other fields are populated as per the model, the dropdown is not showing the saved selected value as per the model. I have used a viewbag to populate the dropdown and that works fine. The states are populated in the dropdown.
ViewBag.StateID = new SelectList(queryStatesInLookup, "LookupID", "LookupCode")
I debugged the razor page and checked. I get the state id from the model (for eg: 8), but this value wont bind to the dropdown. What gives? :/
Apparently the Viewbag cannot have the same name as the property the model ID is bound to. My guess is the CLR is unable to resolve the conflicting names of the dynamic object type Viewbag and the model property name at run time. Thanks :)
When you create your SelectList, you need to pass in the selected value there.
In the example below, replace SelectedValue with your actual selected value.
ViewBag.StateID = new SelectList(queryStatesInLookup, "LookupID", "LookupCode", SelectedValue)

How to you add html attribute options in Yii radio button?

I am trying to use Yii radioButtonList and customize it with an image on top of each radio button.
However, I'm not sure about how to do it and would be grateful if there's any help.
In the documentation:
public static string radioButtonList(string $name, string $select, array $data, array $htmlOptions=array ( ))
for the $htmlOptions=array(), what can you put in there?
I've seen people using 'separator'=> '', can anyone show some examples?
Thanks in advance.
Try:
'htmlOptions'=>array('size'=>100,'class'=>'yourclass')
basically it's:
'htmlOptions'=>array('validHtmlOption'=>'value','anotherValidHtmlOption'=>'value')

Zend Zend_Form Layouting

i have an input-Element, that should be layouted through a css-class:
class="ok", default or when there is no error by validating this field
and
class="error", when there is an error by validating this field.
How can i achieve that?
Fesp
Easiest solution is to foreach through the form elements after you've called isValid and add the class name to each element based on its hasErrors status.
Another solution would be to add a Decorator to the form decorators, which will do the same.