Pass in the logical negation of a boolean to a partial template in dust - dust.js

I Have a partial template that takes a boolean, and I want that boolean to be a negation of a reference I have. So if my reference is true I want the value passed in to be false. Any way I can do this in dust without modifying the partial template?
{>my-partial}
key=!value
{my-partial/}

I solved this by changing the js template helper I was using to pass in the intended reference

Related

which HTML helper bypasses all templates and renders a simple string?

this question I got from some tests:
Which of the following templated HTML helpers of MVC bypasses all
templates and renders a simple string representation of the specified
model property?
and options:
Display
Label
DisplayText
Editor
as I understand, it means, that which helper displays property as string? The correct answer is Label?
the correct answer is DisplayText and don't get confused with DisplayTextFor which is a strongly typed version of DisplayText and returns the annotation value of your model attribute (if predefined) or null otherwise

When I call html.renderpartial do I need to specify my model on the first line?

I would like to use renderpartial but I'm not so clear on the way it is used. If I just call render partial then is any model sent to that? I want to use the HTML helpers. Is there any difference between using those in renderpartial and in the main razor view?
If the view actually uses a model and you don't provide any, it just end up having a null Model object (so lots of Null Object Reference Exception).
Just go with
#{ Html.RenderPartial("_partialView", PartialViewModel); }
or:
#Html.Partial("_partialView", PartialViewModel)
The differences between the two are indicated here.
HTH, M.

Using a edit template without using Html.EditorFor()

I have a date time picker combination in a edit template that can be used like Html.EditorFor(x => x.ETA) but now I want to use the same template somewhere where I don't have a model that contains a DateTime property. So I tried Html.Editor("DateWithTime", "Arrival") which uses the correct template, but doesn't assign a value to ViewData.ModelMetadata.PropertyName which is something that my template relies on. It sets the id of the textbox which is obviously important.
Is there a way to render the template and assign a id value to the ViewData.ModelMetadata.PropertyName so I can re-use the logic in the template instead of having to copy it?
Maybe use ViewData.TemplateInfo.HtmlFieldPrefix instead of ViewData.ModelMetadata.PropertyName.
I am not sure but I thought that HtmlFieldPrefix an PropertyName have the same value as long as you do not iterate a collection.
You can modify the HtmlFieldPrefix property with the htmlFieldName parameter from Html.Editor.
You can use the UIHint in your model. give it the name of the template you want to use
[UIHint("DateWithTime")]
You still use EditorFor with this.

The difference between html control and controFor

What is the difference between mvc HTML.Control and ControlFor (TextBox, checkbox etc)..
One is strongly typed. If you have a view that expects a model of type Customer with a property "CustomerName", you can render the value with either way
<%=Html.Label("CustomerName") %>
<%=Html.LabelFor(a => a.CustomerName) %> //strongly typed
With the second method (lambda expression), you avoid magic strings. You also have the ability to inspect ModelMetadata to perform additional customizations.
Read about Model metadata here:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html
The For versions of the HTML helper methods take properties as strongly-typed lambda expressions instead of strings.
For example, the following to statements are equivalent:
<%=Html.TextBox("Description") $>
<%=Html.TextBoxFor(m => m.Description) $>
However, if you rename the Description property, the TextBoxFor call will give a compiler error, whereas the TextBox call will not fail until you visit that page.
The following article explains the difference in general:
http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx
Simply put, HTML.ControlFor is strongly typed, which allows use of lambda expressions and automatically takes the nameof the property specified as the name/id of the control.

How do I bind to a specific array element in ASP.NET MVC?

I'm using ASP.NET MVC RC1 and trying to bind a textbox to an object property like so:
<%= Html.TextBox("Comments.Contacts[0].ContactName") %>
It seems like it should work, since this does:
<%= ((MuralProject)ViewData.Model).Comments.Contacts[0].ContactName %>
But alas, the result in the textbox is an empty string. Am I doing something wrong?
The first argument for the text box extension method sets the name of the input element that's eventually created and also tries to get an entry from ViewData/Model (for the model it uses TypeDescriptors / reflection) based on that argument.
The way it does this is just by splitting up the input string at the dots then checking the ViewDataDictionary for specific keys and the Model via reflection so in the case you give it'll try and look for Contacts[0] rather than Contacts and won't pick up your property.
To get around this you just need to supply the actual value of the object e.g.
Html.TextBox("Comments.Contacts[0].ContactName",
Model.Comments.Contacts[0].ContactName)
You can see this yourself if you look at the MVC source and take a peek at the ViewDataDictionary class.

Resources