How to use model on view in Orchard for TextBoxFor? - asp.net-mvc-5

I have model ReservationViewModel for use on view. There are set validation information etc. How to use it on view in methods like TextBoxFor(m => m.FirstName)? Exist any options how to declare model on OrchardCMS view(not in editorTempates but in client side)? If I understand good, orchard use in display method some contentshapes not model.
Thanks for some information.

Shapes are view models, only, they're dynamic objects. The strongly-typed, Lambda-based Html helpers don't work with dynamic objects, which are not strongly-typed. Use the weakly-typed Html helpers. In your example, that would be Textbox("FirstName").
Strongly-typed view models however are perfectly fine in Orchard. In order to determine how to use them in your particular use case, I'd need to know whether you're creating the view model in a controller action or in a driver.

Related

Can we have Multiple partial views with different models inside a single view?

Hi everyone am developing an application using ASP.NET MVC 5 and I want to display different models using partial views inside a single view is that possible or I have to make a model for the parent view that includes all the models of the partials ???
If i understood you want use more than one model per view and this is not possible. You need a object with others objects inside. (like you said a model to the parent view that includes all models of the partials).
Your post maybe duplicated for this:
MVC 5 Multiple Models in a Single View

Whats the Simplest way to pass multiple model to asp mvc View

I want to use a single View file to render all my reports which has Clients Model, Fees Model, Suit Model and other models.
only one model can be passed from view. If you want to pass multiple models(or rather objects) you have a few optoins
Pass on the main model using controller and pass remaining objects as by viewbag like
Viewbag.feesModel = something
Viewbag.suitModel = something
return View(studentModel)
Second options to render individual actions using Html.Action

MVC 5 ViewBag security

I am coding an MVC internet application, and I have a question in regards to using the ViewBag.
In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model.
My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag?
Thanks in advance.
Use your view model.
When the ViewBag was implemented (MVC 3) dynamic typing was new (.NET 4.0) and it was put in just as a side-option to ViewData or to quickly generate a view without the need for additional classes.
Any serious MVC project will take advantage of a model/viewmodel with a strongly typed view.
There are no security concerns with either because both essentially only exist through the controllers lifespan.
There are no security concerns with ViewBag since it is disposed once rendered in the View.
I think the answer really should be "it depends". For example, if you have 6 collections required to populate dropdown lists aand you want to get the data posted back, you should definitely use a ViewModel for this. Since 6 collections will be hard to manage if they are stuffed in ViewBag with no strong typing in the view, especially if another developer comes along later needing to do maintenance to the view.
Generically everything should be done inside a view model. That's what a view model is. A class that you specifically define to meet the requirements of your view. Here is an image depecting when to Use TempData, ViewBag or ViewData

Asp.net Html.Action perfomance

i'm developing an asp.net mvc 5 web application using a page that is compose by around 10 module.
I'm implementing each module using a partialview with Html.action, that calling an action that get data from a web api
My doubt is about performance. Can Html.action destroy performance ?
Thank you
I think it depends upon the data and its dependency over the populated view
Html.Action
Action method is useful when the displaying data in the partial view
is independent from corresponding view model.For example : In a blog
to show category list on each and every page, we would like to use
Action method since the list of category is populated by the different
model.
#{Html.Action("Category","Home");}
Html.Partial
Partial method is useful used when the displaying data in the partial
view is already in the corresponding view model.For example : In a
blog to show comments of an article, we would like to use
RenderPartial method since an article information with comments are
already populated in the view model.
#Html.Partial("_Comments")

Umbraco add custom Document Type

Is it possible to add a custom control to the Document Type? Suppose i couldn't create a multiselect or just a simple textfield control. How could i create a custom one and use that from the Document Type page in Umbraco?
If this is possible, then what steps need to be taken? Because i can add all sorts of config information in the Document Type controls that currently exist in there. Like, when i add a textfield i can gvie it a name, an alias and a validation message (and it has some others options).
Do i have to build the custom Document Type control in a specific way? And how is it saved to the database? How does Umbraco handle that?
Any information on this matter is more than welcome!
Since adding custom document types is native to Umbraco, and judging by the description in your question, I'm going to assume that you are talking about adding custom data types with user controls.
If so, check some of the following links on the subject, it's actually fairly simple:
Creating custom datatypes using the umbraco usercontrol wrapper (I personally used this one)
Custom DataTypes in Umbraco
Creating a custom datatype using the usercontrol wrapper (Video tutorial)

Resources