Problems with OpenForum Index.ascx? - asp.net-mvc

This is the ascx page:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<OpenForum.Core.ViewModels.IndexViewModel>" %>
<%# Import Namespace="OpenForum.Core.Views.ForumViewHelper" %>
<div class="openforum_container">
<%= (Model.IncludeDefaultStyles) ? ForumViewHelper.GetDefaultStyles() : ""%>
<%= (Model.IncludeValidationSummary) ? Html.ValidationSummary() : ""%>
<div class="openforum_actions">
<%= Html.ActionLink("Write A New Post", "Post") %>
</div>
<div class="openforum_search">
<% Html.BeginForm(); %>
Search: <%= Html.TextBox("searchQuery") %> <input type="submit" value="go" />
<% Html.EndForm(); %>
</div>
<div class="openforum_message"><%= Model.Message %></div>
<table class="openforum_maincontent">
<% foreach(var item in Model.Posts ?? new Post[0]) { %>
<tr>
<td class="openforum_title"><%= Html.ActionLink(item.Title, "view", new { id = item.Id, title = ForumViewHelper.ToUrlFriendlyTitle(item.Title) })%></td>
<td class="openforum_user">
<div>created by <%= Html.Encode(item.CreatedBy.Username) %></div>
<div><%= item.CreatedDate.ToString("MM/dd/yyyy hh:mm tt") %></div>
</td>
<td class="openforum_modified">
<div>last post by <%= Html.Encode(item.LastPostBy.Username) %></div>
<div><%= item.LastPostDate.ToString("MM/dd/yyyy hh:mm tt") %></div>
</td>
<td class="openforum_replies">Replies: <%= item.Replies.Length %></td>
<td class="openforum_views">Views: <%= item.ViewCount %></td>
</tr>
<% } %>
</table>
<div class="openforum_index_paging">
<% if ((Model.Posts ?? new Post[0]).Count() > 0) { %>
<span>Page <%= Model.CurrentPage + 1 %> of <%= Model.TotalPages %></span>
<% } %>
<% if (Model.CurrentPage > 0) { %>
<% Html.BeginForm(); %>
<input type="submit" value="<<<" />
<input type="hidden" name="searchQuery" value="<%= Model.SearchQuery %>" />
<input type="hidden" name="page" value="<%= Model.CurrentPage - 1 %>" />
<% Html.EndForm(); %>
<% } %>
<% if (Model.CurrentPage < Model.TotalPages - 1) { %>
<% Html.BeginForm(); %>
<input type="submit" value=">>>" />
<input type="hidden" name="searchQuery" value="<%= Model.SearchQuery %>" />
<input type="hidden" name="page" value="<%= Model.CurrentPage + 1 %>" />
<% Html.EndForm(); %>
<% } %>
</div>
</div>
I keep getting an error: The name 'ForumViewHelper' does not exist in the current context. I am using the OpenForum dll. I called the Html.RenderPartial("Index.ascx").

I think the issue is that "ForumViewHelper" is a class inside the "OpenForum.Core.Views" namespace. Try using this instead...

Related

Searching with mongoid search

i have a 3 models user ,user_role and store .user_role belongs to user and store.i have a member controller where i have a search box one for stores,one for user_role(both are select box)below is method for search in user_role model
def self.filter(params)
filter = params[:search] || {}
user_roles = order(role_type: :asc)
if filter[:name].present?
end
if filter[:email].present?
end
if filter[:role].present?
user_roles = user_roles.where(role_type: filter[:role])
end
if filter[:store_id].present?
user_roles = user_roles.where(store_id: filter[:store_id])
end
user_roles
end
This is my member controller below
def index
if current_user.super_admin?
#total_user_roles = UserRole.filter(params).order(sort_column + " "
+ sort_direction)
#user_roles = #total_user_roles.page(params[:page]).per(10)
else
stores = current_user.user_roles.where(:role_type.in =>
['store_manager', 'merchant']).pluck(:store_id)
#total_user_roles = UserRole.where(:store_id.in =>
stores).filter(params).order(sort_column + " " + sort_direction)
#user_roles = #total_user_roles.page(params[:page]).per(10)
end
respond_to do |format|
format.html
format.csv { send_data #users.to_csv }
end
end
def sort_column
User.attribute_names.include?(params[:sort]) ? params[:sort] :
"first_name"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] :
"asc"
end
My search form in view.Should i change anything here in name and email field or just leave it as itis?
<section>
<div class="col-md-12">
<div class="row">
<section class="content-header">
<div class="white card-2">
<h3>Users</h3>
</div>
</section>
</div>
<div class="form white">
<!-- form start -->
<form class="form-horizontal">
<div class="box-body">
<h3>Search Users </h3>
<div class="col-md-3">
<label class="control-label"
for="order_search_order_number">First Name</label>
<input class="form-control" id="order_search_order_number"
name="search[name]" type="text" value="">
<span class="md-input-bar"></span>
</div>
<div class="col-md-3">
<label class="control-label">Email</label>
<input class="form-control" id="order_search_order_number"
name="search[email]" type="text">
<span class="md-input-bar"></span>
</div>
<div class="col-md-3 input">
<label class="control-label">Roles</label>
<%= select_tag("search[role]",
options_for_select(User::ADMIN_ROLES.map { |e| [e.humanize, e]},
params[:search] && params[:search][:role]), include_blank: true,
class: 'select2') %>
<span class="md-input-bar"></span>
</div>
<div class="col-md-3">
<label class="control-label">Store</label>
<%= select_tag("search[store_id]",
options_for_select(Store.all.order('name ASC').map { |e|
[e.name, e.id] }, params[:search] && params[:search][:store_id]),
include_blank: true, class: 'select2') %>
<span class="md-input-bar"></span>
</div>
</div>
<h4 class="pull-right"> Total Users: <b> <%=
#total_user_roles.count %></b>
</h4>
<br><br>
<div class="box-footer">
<button type="submit" class="btn btn-info">Filter</button>
Clear
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
<div class="col-md-12">
<section class="section-data">
<!-- Section Data Table -->
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-body table-responsive custom-sort">
<table class="table table-striped table-bordered nowrap data-
table" cellspacing="0" width="100%">
<thead>
<tr>
<th><%= sortable 'first_name', "Name" %></th>
<th><%= sortable 'email' %></th>
<th>Store</th>
<th><%= sortable 'role' %></th>
<th>Status</th>
<th>Action</th>
<th>Active?</th>
</tr>
</thead>
<tbody>
<% #user_roles.each do |role| %>
<tr>
<td><%= role.user.name%></td>
<td><%= role.user.email %></td>
<td><%= role.store.try(:name) %></td>
<td><%= role.role_type.try(:humanize) %></td>
<td><%= role.user.pending_invitation? ? "Pending" :
"Accepted" %></td>
<td>
<a class="ion-edit actions" href="/admin/members/<%=
role.id %>/edit"></a>
<% if role.user != current_user %>
<a class="ion-android-delete actions red" data-
sweet-alert-confirm="<%= t(:delete_confirm) %>" data-
method="delete" href="/admin/members/<%= role.user.id %>"></a>
<% end %>
</td>
<td>
<div class="onoffswitch">
<input type="checkbox" name="active" <%= "checked" if
role.user.active %> class="onoffswitch-checkbox" id="<%=
role.user.id %>" data-id="<%= role.user.id %>">
<label class="onoffswitch-label" for="
<%=role.user.id %>">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</tr>
<% end %>
</tbody>
</table>
<div class="pull-right">
<%= paginate #user_roles, :theme => 'twitter-bootstrap-3' %>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
</section>
</div>
now i want to implement search for user name and email ,i tried lots of ways but cant come up with solution.as Iam not expert need some solution from a expert .iam using mongoid search gem.

Iterate 4 Arrays with Rails

I'm new to Rails and I'm trying to build a nice application and I'm struggling with arrays, I have 4 arrays that I want to iterate and they are not the same size
I want to generate sections in HTML using the first array what I did it
#sections = ['Section One','Section Two','Section Three','Section Four']
#itemsOne = ['item 1','item 2','item 3','item 4','item 5','item 6']
#itemsTwo = ['item 1','item 2','item 3','item 4','item 5','item 6']
I was using
<%= #sections.zip(#itemsOne, #itemsTwo).each do |t1, t2, t3| %>
<%= t1 %>
<table>
<tbody>
<tr>
<td>
<%= t2 %> | <%= t3 %>
</td>
<td>
<%= t2 %> | <%= t3 %>
</td>
<td>
<%= t2 %> | <%= t3 %>
</td>
</tr>
</tbody>
</table>
<% end %>
I have a table that have a Section Title and cells that have two values
but what I get is the value of |t2| in each cell of |t1| section
using #Phil answer down below, but he deleted it.
<%= #sections.zip(#itemsOne, #itemsTwo).each do |t| %>
<%= t[0] %>
<table>
<tbody>
<tr>
<td>
<%= t[1] %> | <%= t[2] %>
</td>
<td>
<%= t[1] %> | <%= t[2] %>
</td>
<td>
<%= t[1] %> | <%= t[2] %>
</td>
</tr>
</tbody>
</table>
<% end %>
p.s. the itemsOne and itemsTwo arrays have more than 20 values.
What I created is separated my big arrays into smaller ones and then Iterated thru each this way without a Table because table was making design issues so i went into div's using bootstrap 3 column, there might be a better way but this is what i got as a beginner.
<div class="row">
<div class="col-md-12">
<h4><%= #Sections[0] %></h4>
<!-- This will Display Section 0 in the Array -->
</div>
<div class="row">
<div class="col-md-12">
<% #count = 0 %>
<!-- Counter is Zero -->
<% #ItemsOne.collect do |t1| %>
<!-- This will loop array to increment the #count and repeat the HTML -->
<% #count += 1 %>
<!-- With each loop increment by 1-->
<div class="col-md-3">
<div class="col-md-12">
<label>
<input type="checkbox" name="optionsCheckboxes">
<%= #ItemsOne[#count - 1] %>
<!-- Counter should start from 0 adding -1 will make it start
from 0 instead of 1 and then will print the value of the Index Number -->
</label>
</div>
</div>
<% end %>
</div>
</div>
</div>
Here is another way to do this
<div class="row">
<% #Sections.each_with_index do |x1, n| %>
<div class="row">
<div class="col-md-12">
<h4><%= #Sections[n] %></h4>
</div>
<div class="row">
<div class="col-md-12">
<% if n == 0 %>
<% #itemsOne.each_with_index do |t1, n| %>
<div class="col-md-3">
<div class="col-md-12">
<label>
<input type="checkbox" name="optionsCheckboxes">
<%= #itemsOne[n] %>
</label>
</div>
</div>
<% end %>
<% elsif n == 1 %>
<% #itemsTwo.each_with_index do |t1, n| %>
<div class="col-md-3">
<div class="col-md-12">
<label>
<input type="checkbox" name="optionsCheckboxes">
<%= #itemsTwo[n] %>
</label>
</div>
</div>
<% end %>
<% elsif n == 2 %>
<% #itemsThree.each_with_index do |t1, n| %>
<div class="col-md-3">
<div class="col-md-12">
<label>
<input type="checkbox" name="optionsCheckboxes">
<%= #itemsThree[n] %>
</label>
</div>
</div>
<% end %>
<% elsif n == 3 %>
<% #itemsFour.each_with_index do |t1, n| %>
<div class="col-md-3">
<div class="col-md-12">
<label>
<input type="checkbox" name="optionsCheckboxes">
<%= #itemsFour[n] %>
</label>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
<% end %>
</div>

advanced Search (checkboxes and selection)

I'm having a problem with my advanced search.
Essentially, its an advanced search for bands (name, style, bandpicture by checkboxes (checked: have a bandpicture))
Here is the code.
result.html.erb
<table >
<colgroup>
<col width="250" />
</colgroup>
<tr>
<td>
<label for="name">Filter</label></br>
<%= form_tag band_path do %>
<label for="Style">Style</label></br>
<%= select_tag :style_id, options_from_collection_for_select(Style.all, :id, :name, params[:style_id]), include_blank: true, class: "form-control" %>
<br>
</br>
<%= check_box_tag 'options[]', "picture" %>
<%= button_to '#', class: 'btn btn-default' do %>
<%= t(:find) %>
<% end %>
<% end %>
</td>
<td>
<div>
<% #bands.each do |band|%>
<div class="top-bar">
<div class="center">
<div class="info">
<div class="name"><%=band.id %></div>
<div> <%= band.zip %>, <%= band.city %> </div>
</div>
<div class="desc">
<table>
<tr>
<td>Styles</td>
<td>
<% band.styles.each do |s| %>
<%= s.style.name %>
<% end %>
</td>
</tr>
</table>
</div>
<% end %>
</td>
</tr>
</table>
models band.rb
def self.search1(style_id)
Profile.joins("...").where("style_id = ?", style_id)
end
controller.
def searchresult
if params[:style_id].present?
#bands = Band.search1 params[:style_id]
elsif params[:options]
Band.where(:options => #filtered_options)
else
#bands = Band.all
end
end
The searchresult don't show the result of the checkboxes and I have this errors:
undefined method `search1' for #<Class:0x00000008eb5548>

how to get data from my forms

i'm trying to get the data of my forms on my post metod using
public ActionResult EntradaPedidos(FormCollection formulario) {
Pedidos miPedido = new Pedidos();
UpdateModel(miPedido);
miPedido.division = Request.Form["division"];
what i'm doing wrong? i link my model in the view, and try using different forms.
http://imageshack.us/photo/my-images/13/sinttuloamq.png/
http://imageshack.us/photo/my-images/585/sinttuloecp.png/
this is my view
<% using (Html.BeginForm("EntradaPedidos","home",FormMethod.Post )){ %>
<% =Html.ValidationSummary("") %>
<p>
<label>Division: </label>
<%= Html.DropDownList("division", (SelectList)ViewData["divisiones"]) %>
<!--<%= Html.TextBox("clave1", Model.clave1) %>-->
</p>
<p>
<label>Número del pedido: </label>
<label id="numPedido"><% =Html.Encode(Model.numPedido) %></label>
<!--<% =Html.TextBox ("numeroPedido") %>-->
</p>
<p>
<label> Fecha: </label>
<% =Html.TextBox ("FechaInicio") %>
</p>
<p>
<label>Tipo de pedido: </label>
<% =Html.RadioButton ("tipoPedido", "1") %><label class="inline" for="TipoPedido">1</label>
</p>
<p>
<label>Transacción de pedido: </label>
<% =Html.RadioButton("transPedido", "D2") %> <label class="inline" for="TransPedido">D2</label>
</p>
<p>
<label>Codigo del cliente :</label>
<% =Html.TextBox ("codigoCliente") %>
<label id="lbNombreCliente">Nombre del Cliente: </label>
</p>
<p>
<label>Bodega: </label>
<% =Html.RadioButton("bodega", "CD") %><label class="inline" for="Bodega">CD</label>
</p>
<p>
<label>Lista de Precios: </label>
<label id="lbListaPrecios"> </label>
<%= Html.DropDownList("ddListaPrecios") %>
<!-- <%= Html.CheckBox("cbCambioLista") %> <label class="inline" for="cbCambioLista">Desea cambiar lista de precios?</label> -->
</p>
<p>
<label id="lbCondPago">Condiciones de Pago: </label>
</p>
<p>
<label>Vendedor: </label>
<%= Html.DropDownList("ddListaVendedores") %>
</p>
<p>
<label>Concepto Contable: </label>
<label id="lbConContable"> 03 </label>
</p>
<p>
<label>Ciudad: </label>
<% =Html.DropDownList ("ddCiudad") %>
<label>Punto de entrega: </label>
<%= Html.DropDownList("ddPuntosEntrega") %>
</p>
<p>
<input type="submit" value="Siguiente"/>
</p>
<p>
<%= Html.ActionLink("Menu opciones" , "Menu") %>
</p>
<%} %>
Pass your model to the View:
var pedidos = new Pedidos { division = "teste" };
return View(pedidos);
then tell the view what is its model:
<%# Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcProject.Models.Pedidos>" %>
and expect it on your action method
public ActionResult EntradaPedidos(Pedidos miPedido) {
var division = miPedido.division

asp.net mvc - How to find exactly which button was clicked when button names are all identical?

I've got the following code in my aspx file:
<% using (Html.BeginForm())
{
int i = 0;
%>
<% foreach (var item in Model.Educations)
{ %>
<fieldset>
<input type="hidden" name="educations.Index" value="" />
<p>
<label for="PID">
PID:</label>
<%= Html.TextBox("educations["+i+"].PID", item.PID)%>
<%= Html.ValidationMessage("PID", "*")%>
</p>
<p>
<label for="EducationType">
EducationType:</label>
<%= Html.TextBox("educations["+i+"].EducationType", item.EducationType)%>
<%= Html.ValidationMessage("EducationType", "*")%>
</p>
<p>
<label for="SchoolName">
SchoolName:</label>
<%= Html.TextBox("educations["+i+"].SchoolName", item.SchoolName)%>
<%= Html.ValidationMessage("SchoolName", "*")%>
</p>
<p>
<label for="UniversityId">
UniversityId:</label>
<%= Html.TextBox("educations["+i+"].UniversityId", item.UniversityId)%>
<%= Html.ValidationMessage("UniversityId", "*")%>
</p>
<p>
<label for="Department">
Department:</label>
<%= Html.TextBox("educations["+i+"].Department", item.Department)%>
<%= Html.ValidationMessage("Department", "*")%>
</p>
<p>
<label for="Degree">
Degree:</label>
<%= Html.TextBox("educations["+i+"].Degree", String.Format("{0:F}", item.Degree))%>
<%= Html.ValidationMessage("Degree", "*")%>
</p>
<p>
<label for="YearOfGraduation">
YearOfGraduation:</label>
<%= Html.TextBox("educations[" + i + "].YearOfGraduation", String.Format("{0:F}", item.YearOfGraduation))%>
<%= Html.ValidationMessage("YearOfGraduation", "*")%>
</p>
<p>
<label for="ID">
ID:</label>
<%= Html.TextBox("educations[" + i + "].ID", item.ID)%>
<%= Html.ValidationMessage("ID", "*")%>
</p>
<input type="submit" name="silButton" value="Sil"/>
</fieldset>
<%
i++;
} %>
<p>
<input type="submit" name="ekleButton" value="Ekle" />
</p>
<% } %>
<div>
<%=Html.ActionLink("Back to List", "Index") %>
</div>
This way I'm able to dynamically add ("Ekle") more fields if user wants to enter additional education information (most probably from another university or another degree).
This code also give "Sil" button (which means delete), and I want to be able to detect exactly which "Sil" button was pressed and delete that Education entry from my "object" in session.
My action method looks like this:
public ActionResult Step3(string ekleButton, IList<Education> educations, IList<string> silButton)
{
if (educations != null)
{
_person.Educations.Clear();
_person.Educations.AddRange(educations);
}
if (ekleButton != null)
{
_person.Educations.Add(new Education());
}
if (silButton!=null){
//find index and delete it from _person.Edications
}
return View(_person);
}
In this way silButton != null if any of the "silButton" buttons was pressed and I can't detect which button was pressed. Is there a way to find this out?
You could put the index in the name of the button:
<input type="submit" name="silButton<%=i %>" value="Sil" />
And in your action method:
var silButton = Request.Params.AllKeys.FirstOrDefault(key => key.StartsWith("silButton"));
if (!string.IsNullOrEmpty(silButton))
{
var index = int.Parse(silButton.Replace("silButton", string.Empty));
}

Resources