I am using mvc, and I have created a controller for the custom widget which will allow the user to choose the image that they watn displayed. How do I specify this field?
I have:
public class Test: Controller
{
public ImageSelector Image { get; set; }
}
You need the so called custom designer for your MVC widget.
Check this article for all the steps/details you need:
https://www.progress.com/documentation/sitefinity-cms/image-selector-mvc
UPDATE: Here is Github Gist with working code:
https://gist.github.com/VesselinVassilev/31b159a1985f272e85b4ff167e59c8d8
Note: the DemoController.cs file should be in the /mvc/controllers folder
the rest of the files should go to the /mvc/views/demo/ folder.
Related
I want to change some code in an action of the CategoryNavigation action from the CatalogController. I don't want to alter the core code of NopCommerce so i need to try to overide the code with my own custom code and this i want to do with my plugin.
What I basically want is the same function of the original code but
with some custom tweaks.
I am having this class:
public partial class NumberofVisittoProducts : BaseEntity
{
public int ProductId { get; set; }
public int ProductVisitStatistics{ get; set; }
}
So i want to increment ProductVisitStatistics Value when Particular Product Detail page is open.
So far i have successfully managed to create this table with my
plugin.
I have tried to study alot regarding overriding a Controller from the below link:
How to implement an Action Filter in NopCommerce
Very Close but not quite able to override core view nopcommerce
http://www.nopcommerce.com/boards/t/24127/overriding-other-controllers-and-their-routes.aspx
So I am so much confused between the two.
Now say i use Action filter then I am not getting it how do i get that Particular ProductId then.
For 2nd Method that is override the Route i am not getting that how do i use it and perform my functionality like update ProductVisitStatistics in my table.
So If anybody can Please help me with this??
I am ready to send my plugin project if anybody wants to see what i have done.
I am creating an application using mvc4. In my application i created the resource.resx file outside the project (but in one solution where my mvc application is also reside) in class library. I want to use the label name or validation message from resource.resx file.
Like:-
public class xyz
{
[Display(Name = "LBL_name", ResourceType = typeof(Resource.abcd.Resource1))]
public string Name1 { get; set; }
}
"LBL_name" is specified in Resource1.resx file. "Resource.abcd" is its custom tool namespace.
I added the reference of class library to my mvc application and set the properties of resource.resx as suggested in this link.
But it gives the following error
Cannot retrieve property 'Name' because localization failed.
Type 'Resource.abcd.Resource1' is not public or does not contain a
public static string property with the name 'LBL_name'.
I am not sure of using the resource.resx file correctly. Can someone guide me one this.
Open the file in the resource editor in VS and make sure the access modifier param is set to Public.
I have a small MVC web project where I want to be able to achieve the following:
Select the base page layout and CSS/JavaScript based upon the active domain
Optionally allow this base/default setting to be overridden at the start of the session.
To help achieve this I have created a layout object with the following properties:
public class PageLayout {
public string Reference { get; set; }
public string Domain { get; set; }
public string LayoutPath { get; set; }
public string CssPath { get; set; }
public string JavaScriptPath { get; set; }
}
My idea being that at the start of the session, the URL will be checked for a layout parameter. For example:
http://www.{Domain}.com/tech
In this instance, the Pagelayout object with the Reference "tech" would be retrieved. If no parameter was found then the Page Layout object with its Domain property matching the active domain would be retrieved.
I have several questions regarding the right way to implement this:
Where is the best place to implement this logic in MVC? The Session_Start method in Global.asax seems like a potential candidate
I want to persist the retrieved PageLayout object across the whole session. I was going to add it to the Session state via some kind of management class.
How do I make the Pagelayout data available to each page. I thought about creating a custom Controller and then adding it to the ViewBag (from the Session), so the master view could implement something like the following:
#{
Layout = ViewBag.Pagelayout.LayoutPath;
}
...
Are the better/cleaner/more appropriate mechanisms available to achieve what I need?
Yes there are cleaner ways to do, like using some third party tool and to hook it your application.
You can take a look at this site, this is the latest that have been introduced recently
http://razorc.net/
Also take a look at
http://www.codeproject.com/Articles/32847/ASP-NET-MVC-Dynamic-Themes
http://codeofrob.com/entries/dynamically-switching-between-master-pages-in-asp.net-mvc.html
I would like to add a new part to orchard administration area,
I need an iframe in this part, that shows another page in another website.
*page, and other custom content type is not what I need.
Is it possible to create something like that?
Thanks,
NadavSt
Perfectly possible.
You will need a custom module. With a controller called AdminController.
Add a method called Index and a new view in the views folder called Index.cshtml and do whatever you want in there.
public ActionResult Index() {
//do stuff...
return View();
}
Then to create a link to it in the menu, add a file called AdminMenu.cs in the root of your module with something like the following.
public class AdminMenu : INavigationProvider
{
public Localizer T { get; set; }
public string MenuName { get { return "admin"; } }
public void GetNavigation(NavigationBuilder builder)
{
builder
.Add(T("My Admin Area"), "4", item => item.Action("Index", "Admin", new { area = "Orchard.MyModule" }).Permission(StandardPermissions.SiteOwner));
}
}
So that creates a item in the menu called "My Admin Area" at position 4 that links to a method called Index in the Admin controller. You can add permissions so the item only appears for those users with that permission. Make sure you protect your action in the controller as well.
I would recommend checking random Core modules to see how they do stuff, it is the best way to see how things work and get examples. Most modules implement the functionality you are after.
Good luck :)
I have a model that looks like this:
public class Book
{
public string Name { get; set; }
public IEnumerable<Author> Authors { get; set; }
}
public class Author
{
public string FullName { get; set; }
public DateTime BirthDate { get; set; }
}
I have a form in a view for editing a book. The section for editing the Authors collection is in a partial view. The form fields are generated with the Html.EditorFor() method.
It works well for editing existing data. What I would like to do is to put in the Authors editing partial view multiple blank entries that if the user fills them they will be added as new items to the Authors collection.
The final view should look something like this:
http://s1.postimage.org/6g9rqfp20/image.jpg
What is the correct way to achieve this behavior?
If you are using MVC2 this is your best bet
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx#related-results
I am not sure how interested you are in using javascript libraries to get what you are looking to get done, but here is a great example of what you are trying to do: Contact Editor Example
It uses the knockouts library which allows you to work with JavaScript data binding. This also gives you a nice thick application feel on the web which users generally like.
If you are still curious about how this works with serverside, you can look at this presentation from Mix11
Good luck.