I have helper:
public static function addSubmenu($submenu){
JSubMenuHelper::addEntry(JText::_('Start'),
'index.php?option=com_compn');
JSubMenuHelper::addEntry(JText::_('Menuitem'),
'index.php?option=com_compn&view=dcrs',
$submenu == 'dcrs');
and I want to put below of them another bar with my custom links. How to do it?
Related
I am trying to create a custom control for webview, i am trying to get a checkbox inside a webview Reason :- we have a bunch of text to be displayed and unless the user reaches the end of the scroll he cannot move to the next page and at the end of the scroll there is a checkbox where user has to check the the checkbox and then he can process. here i have tried putting the checkbox and webview inside the stacklayout but the issue is webview have its own scroll bar and and stacklayout scroll bar does not work when a user try to scroll as the webview scroller scrolls out also when i try to close the Webview Page with back button the webview gets close and not the page
i am not sure what approach should i apply here.
i am getting my html data from my webapi.
anyone with some solution would be appreciable
here is my custom renderer which i have wrote but the piece missing here is how can i add another xamarin control inside this
public class CustomPdfViewRenderer : WebViewRenderer
{
public CustomPdfViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Settings.BuiltInZoomControls = true;
Control.Settings.DisplayZoomControls = false;
Control.Settings.LoadWithOverviewMode = true;
Control.Settings.UseWideViewPort = true;
}
}
}
You can try the following approach:
Add checkbox to HTML
When the user check checkbox call some JavaScript function
When JavaScript function is called, call C# function (Xamarin) which will enable the user to process to the next page (or some other Xamarin side stuff)
Here is how you can call C# function from JavaScript :HybridWebView
I have a UserControl say - GiveIdentity.ascx (it has 2 TextBox fields SSN and DOB)
I have another UserControl say - GiveIdentityList.ascx (basically this is a repeater rendering say 3 instances of GiveIdentity UserControl)
Now I have this GiveIdentityList UserControl on say Default.aspx page.
I want to ipliment a 'IsValid' property or method.. on the GiveIdentity.ascx control itself... so that it would retrun whether all textbox fields on that particular control are valid or not... (remember I don't wanna user Page.Validators() or something on the Default.aspx page) - I want the UserControls which are inside another UserControls which is a repeater - to expose the IsValid property - suggesting that all text and date controls inside itself are valid or not....
I appreciate your help... Thanks
You can expose a public method in your user control to any page that uses the control. You should also add an event to alert the parent pages if the state changes. Adding these methods are easy enough:
Partial Class user_controls_myControl
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End sub
Public Function isValid() as boolean
if(me.checkbox1.text<>"" andalso me.checkbox2.text<>"") then
return true
else
return false
end if
End sub
end Class
Now, in your ASPX page that holds all of these controls, you can check that specific function to make sure they are valid. For instance, if you have a user control called giveIdentity1, you'll want to iterate over the repeater and cast an object to your user control type. You can then check the isValid function like this:
dim getBool as boolean
getBool = me.giveIdentity1.isValid
If you need help iterating over the repeater, let me know
You can also create your own server events to register changes. You can read a post to a similar topic I responded to here: Handling events of usercontrols within listview
If this does not answer your question, let me know.
The scenario is that I want to populate the navigation bar, the menu, with Mvc.Sitemap.
How should I achieve this?
It feels strange to add a View Model onto the layout page. And that may cause a view to have more than one View Models.
can any one help? Thank you.
Update: ----------
I have Home/_Menu as a partial view which uses MenuViewModel. But how can I include that View in _layout?
I cannot simply use #Html.Partial("_Menu") inside my _Layout.cshtml because I need to specify the controller and action where the view model is built. What is the correct way to do this?
And if I do #Html.RenderAction("_Menu", "Home"), I get a Object reference not set to an instance of an object. error on the Model.
You should not have a model in your Layout, because then every view that you call from there by default will have this model. Instead you should create a Menu view with the model, and when you call it pass a new MenuModel to it as a model.
Edit:
You can have a class that will pull data out of where you store your menu values. Then you call your partial like this:
#Html.Partial("_Menu_", menuobject.Root)
And the class:
partial class menuobject
{
public static menuobject Root
{
// MenuRoots are all roots that have ID -1 - which will be the root
return MenuRoots.Single(x => x.Something == "Topnavi"); // this will return the root above all your menus
}
}
Than in your view you go foreach() on each level of menus to populate them.
I'm writing an MVC 3 app and I have tried to code a control in the Controller (due to permissions, different menu items will be visible for different users) and use the object in the Razor page. For example, in the Controller I do something like:
public ActionResult Index()
{
var menu = "#(Html.Telerik().Menu().Name("menu").Items("menus => { menus.Add().Text("Home").Action("Index", "Home"); menus.Add().Text("Deliveries").Action("Index", "Delivery"); }))";
var model = new MenuModel()
{
Menu = menu
};
return View(model);
}
And in the View I try to render the Menu using #Model.Menu but I just get the string value rather than an actual menu. Is what I'm trying to do possible?
Extend the HtmlHelper class and use the newly created method to render your menu in the View:
Helper:
public static string RenderMenu(this HtmlHelper html)
{
var menu = new StringBuilder();
/* ... menu rendering logic ... */
return menu.ToString();
}
View:
#Html.RenderMenu();
Nevertheless, it is fine to put this logic in the view. Using the HtmlHelper extension just separates/cleans the code.
I wouldn't want to do it that way even if it were possible!
You should decouple your controller and view more than you are currently doing.
The controller should only pass data the view requires. If the view needs a menu with different menu items then use the controller to decide what menu items the view should have then add them to a list object and pass that list to the view. The view will then build a menu based on the list of menu items.
Also when I say "menu items" I don't mean markup! I mean create a new MenuItemViewModel object to persist your data between your controller and your view e.g pseudo code:
public class MenuItemViewModel { string url, string text }
List<MenuItemViewModel> menuitems ...
return View(menuitems)
Why would you want to do this? This is breaking the separation of concerns in MVC - your controller shouldn't worry about how the menu is displayed, just getting the right data to the view for display.
If you want to do security trimming, don't pass in a builder string. There are other methods available.
You could try the MVC SiteMap provider which can handle security trimming against the [Authorize] controller attributes (bit of work to learn and setup, but great once its there).
Pass in your own collection of flags or pre-build menu items, like what Greg suggested.
Make a HtmlHelper extension, something like 'IsAuthorized()' that will check against the controller authorize attributes. Here's a gist of one I used to use before switching to the MVC Sitemap.
With the html helper, you can do this:
#(Html.Telerik().Menu()
.Name("Menu")
.Items(m =>
{
#* Publicly Accessible Controller *#
m.Add()
.Text("Home").Url(Url.Action("Index", "Home"));
#* Secure Controller *#
if (Html.IsAuthorized<MyProject.Controllers.SecureController>(c => c.Index()))
{
//m.Add()....
}
.....
Struggling on in my first MVC project, I need to show a menu of steps for a wizard. The problem is that some of the steps depend on the data that the user provides.
So say for example, if a user pays cash, we skip the page that shows bank-account information (and thus remove the menu-item)..
I have a "page" class in C#, and a "menu" class that has a list of "pages". I'm going to write the logic that dictates whether or not to show a menu-item in the menu class.
The problem is this;
The page class is a very simple class that looks like this ("active" means the menuitem is highlighted as the currently active item):
public class Page
{
MvcHtmlString Link { get; set; }
bool Active { get; set; }
bool Visible { get; set; }
public Page(MvcHtmlString link)
{
Link = link;
Active = false;
Visible = true;
}
public Page(MvcHtmlString link, bool active, bool visible)
{
Link = link;
Active = active;
Visible = visible;
}
}
In my logic I want to add pages to the list, and I'd like to use the "Link" property of a page to store the target URL for each menu-item. This way I can fill that property using Html.Actionlink() and all its available parameters to generate the HTML for the link.
In the eventual menu I can just iterate and show the items.
It also has the advantage that I could do an AJAX call to this function and receive HTML back I can use in my page to update the menu dynamically.
However, Html.ActionLink is not available, and in other posts on Stackoverflow I found that people also dislike using a html helper outside of an MVC view, for understandable reasons.
So my question is; how would I go about this in a clean solution? I considered giving the page class not a Link property, but "controller" and "action" properties, but I would be missing out on the flexibility of adding a class or other HTML attributes easily, which the actionlink DOES provide.
Thanks,
Erik