My controller has to enumerate all the areas in the application. Is it possible? And how?
From this issue, something like that =>
RouteTable.Routes.OfType<Route>()
.Where(r => r.DataTokens != null)
.Select(r => (string) r.DataTokens["area"]);
Related
How do I add a 2nd WHERE clause ('AND') in my current ViewBag with LINQ in Controller? Thanks!
ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
Where(o => o.TYPE== "4").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");
You can add && with WHERE like this way.
ViewBag.Subjects = new SelectList(_odb.SUBJ_MSTR.
Where(o => o.TYPE== "4" && o.TYPE=="5").OrderBy(o => o.SUBJ_NAME), "SUBJ_ID", "SUBJ_VAL");
I'm using Infragistics on an Entity Framework code-first MVC project. I want to display a table with a hidden column (the ID) and it has to be editable. Here is what I've got so far:
<table id="igTests"></table>
#(Html.Infragistics().Grid<BusinessModel.VO.TestVO>().ID("igTests")
.AutoGenerateColumns(false)
.Columns(column =>
{
column.For(x => x.TestId).DataType("int").HeaderText("id");
column.For(x => x.TestNum).DataType("int").HeaderText("Test num");
column.For(x => x.Type).DataType("string").HeaderText("Type");
column.For(x => x.Nature).DataType("string").HeaderText("Nature");
column.For(x => x.TeamName).DataType("string").HeaderText("Team");
column.For(x => x.CreateDate).DataType("date").HeaderText("Creation date");
})
.Features(feature => {
feature.Sorting().CaseSensitive(true);
feature.Filtering().Mode(FilterMode.Simple);
})
.PrimaryKey("TestId")
.DataSource(Model.TestsVO.AsQueryable())
.DataBind()
.Render())
This is what is displayed:
Now lets add the update feature (i know the readOnly is useless since we are not supposed to see it):
feature.Updating().EnableAddRow(true).EnableDeleteRow(true).EditMode(GridEditMode.Row).ColumnSettings(settings =>
settings.ColumnSetting().ColumnKey("TestId").ReadOnly(true)
);
And hide my ID-column:
column.For(x => x.TestId).DataType("int").HeaderText("id").Hidden(true);
Here is what i get. As you can see the table acts like my ID-column was visible.
This happened when I added the update feature. Do you have any idea on how I could fix the "Add new row" row acting like my column was visible? Thanks in advance.
Probably you should add this
}).Features(features => features.Hiding()
.ColumnSettings(settings =>
{
settings.ColumnSetting().ColumnKey("id").Hidden(true).AllowHiding(false)
http://www.infragistics.com/products/jquery/sample/grid/column-hiding-on-initialization
I got it to work using .Width("0px") and ReadOnly on my ID-column. A bit dirty but had no other choice...
In my ASP.NET MVC application I am using a select list control to generate a list for a multiselect widget:
<%=Html.ListBoxFor( m => m.Product.Name,
new SelectList(
Model.Products.Where(
s => !Model.Product.Any(
t => t.Id == s.Id.Value
) ).OrderBy( t => t.Name ), "Id", "Name",
new { multiselect = "multiselect", #class = "fancySelect products"} ) ) %>
Which will generate a list of items. The problem is that some of them need encoding:
<span>Cōnetic™ Technology</span>
If I render this item directly to the UI using a simple response.write I see this:
<p class="c">Cōnetic™ Technology</p>
How would I go about integrating an Html.Encode into my select list statement to produce the same encoding result? Or is there a better encoding method that will effect select lists on a global level?
This is MVC 2 btw, so no razor.
You need to encode data before displaying, and it should render as expected.
Here you example which we used in our asp.net mvc2 project:
<%= Html.Encode(ViewData["PasswordLength"]) %>
It is in a namespace System.Web.Mvc, and it converts the specified string to an HTML-encoded string.
I currently have a product view page that contains an MVCContrib HTML Grid with a select link at the beginning of each row. If the select link is clicked, it takes me to a different page.
My question is whether it is possible to retrieve the productID from the row that is selected and pass that to the next page.
Maybe this is posible to do with a session variable but im not sure.
Any help would be greatly appreciated.
Thanks in advance.
Here is my view code:
<% Html.Grid((List<System2__MVC2.Controllers.ProductController.ProductsSet>)ViewData["Products"]).Columns(column =>
{
column.For(c => Html.ActionLink("Select", "Products", "Product")).DoNotEncode();
column.For(c => c.ProductID);
column.For(c => c.Name);
column.For(c => c.Description);
column.For(c => c.Price);
}).Render();
%>
Maybe I'm misunderstanding your question, but couldn't you just pass the ProductID as a route value to the ActionLink method? Something along the lines of:
Html.ActionLink("Select", "Products", "Product", new { ID = c.ProductID }, null)
What is the way to sort Telerik's RadGrid ? I don't want to add a form server tag, and I don't want to use a user control with code behind like an example I've seen (since I think these are not true MVC solutions, am I right ?).
Please point me to an example or post example code...
Thanks in advance.
For your telerik questions you should go to http://www.telerik.com/community/forums.aspx
Their support is great and if the forums don't cut it just send a formal request, you will need to create a demo project with your problem. I have used telerik products for years and they never fail to answer your question within a few days.
The demo site is also a great source of knowledge (linked above by robert)
Guido
I am using the ASP.NET MVC open source Telerik controls. Here is an example of how I'm using the sort. It works for server control or Ajax but I've found that the Ajax grid is more touchy as far as it creating circular reference errors.
This Ajax example sorts by two columns. The logic is the same for server binding.
#(Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.category_id ))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("AjaxGridSelect", "CategoryTree")
.Insert("GridInsert", "CategoryTree", new { GridEditMode.PopUp, GridButtonType.ImageAndText })
.Update("GridUpdate", "CategoryTree", new { GridEditMode.InLine, GridButtonType.ImageAndText })
.Delete("GridDelete", "CategoryTree", new { GridEditMode.InLine, GridButtonType.ImageAndText }))
.Columns(columns =>
{
columns.Bound(p => p.category_name).Width(150);
columns.Bound(p => p.status_cd).Width(100);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.ImageAndText);
commands.Delete().ButtonType(GridButtonType.ImageAndText);
}).Width(180).Title("Commands");
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Pageable(paging => paging.PageSize(50)
.Style(GridPagerStyles.NextPreviousAndNumeric)
.Position(GridPagerPosition.Bottom))
.Sortable(o => o.OrderBy(sortcol =>
{
sortcol.Add(a => a.category_name);
sortcol.Add(a => a.add_date);
})
.Filterable()
.Groupable()
.Selectable())