How to arrange partials in parent view using bootstrap in MVC4? - asp.net-mvc

I have 4 partials and want to put these partials in the parent view. Currently, I am using a container to put all the partials together but I want to display the partials in the given order which I have shown in the code.
<div class="col-md-7">
<div class="panel panel-default">
<div class="panel-heading">
ABC
</div>
<div class="panel-body">
</div>
<div id="container">
#{ Html.RenderPartial("_PartialABC", Model); }//Currently I am displaying all the partials here
// Want to display _PartialA here
</div>
</div>
</div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
// Want to display _PartialB here
</div>
<div class="panel-body">
// Want to display _PartialC here
// Want to display _PartialD here
</div>
</div>
_Partials
#model Aplication.Models.ABC.ClsA
<div id="myA">
#{ Html.RenderPartial("_PartialA", Model.firsts); }
</div>
<div id="myB">
#{ Html.RenderPartial("_PartialB", Model.seconds);}
</div>
<div id="myC">
#{ Html.RenderPartial("_PartialC", Model.thirds);}
</div>
<div id="myD">
#{ Html.RenderPartial("_PartialD", Model.fourths);}
</div>

Related

How can i create view using bootstrap in mvc

I am new to bootstrap, how can i create view shown in image.a corosel has number of boxes[enter image
Use this template for get the image. You can edit it on top of this structure.
<div class="container">
<div class="row row-cols-5">
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
<div class="col p-5">Column</div>
</div>
</div>

Can Bootstrap panel be reordered in different sequence when seen in mobile?

I want to display the panel in the same way when displays in desktop view but want to change the sequence when seen in mobile.In mobile view, the first panel First Name and the last panel Last Name should be seen one after another. I googled it but could not found the solution. Please help me.
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">First Name</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Address</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Company</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Last Name</div>
</div>
</div>
Yes, this is done with Bootstrap's order classes.
Bootstrap 4.0+
You can use order-1 through order-12 and the col's will be ordered from 1-12. To set responsive break points in this you can use them like order-sm-6 and order-sm-7.
In your code, to move the lastName to the second slot you would reorder them and set the order custom for the breakpoint and higher like so:
<div class="container active col-md-4 col-sm-6 order-md-1">
<div class="panel panel-default">
<div class="panel-heading">First Name</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6 order-md-4">
<div class="panel panel-default">
<div class="panel-heading">Last Name</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6 order-md-2">
<div class="panel panel-default">
<div class="panel-heading">Address</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6 order-md-3">
<div class="panel panel-default">
<div class="panel-heading">Company</div>
</div>
</div>
Putting them in the current order you have on md and up.
https://getbootstrap.com/docs/4.0/layout/grid/#order-classes Has more information.
Bootstrap 3
Ordering is done with push/pull.
So col-md-push-3 would push the column over 3/12 if it could snap. An example below being the columns are rendered in code order below md, but are reversed md and above:
<div class="row">
<div class="col-md-9 col-md-push-3">.col-md-9 .col-md-push-3</div>
<div class="col-md-3 col-md-pull-9">.col-md-3 .col-md-pull-9</div>
</div>
In this case (pushing last name back to the end for md and up):
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">First Name</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6 col-md-push-8">
<div class="panel panel-default">
<div class="panel-heading">Last Name</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Address</div>
</div>
</div>
<div class="container active col-md-4 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Company</div>
</div>
</div>

Bootstrap columns not aligned properly

Currently I am making a twitter clone using RubyOnRails and bootstrap as the framework. When trying to distribute some text in a post panel using the "col-sm" div class, the text seems jammed together on the left,
as seen here.
Here is my code:
<div class="row">
<div class="col-xs-3">
<div class="panel panel-default">
<div class="panel-body">
<p>status</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<p>trend</p>
</div>
</div>
</div>
<div class="col-xs-6">
<%= render '/components/post_form' %><br></br>
<% for #p in #posts %>
<div class="panel panel-default post-panel">
<div class="panel-body">
<div class="col-sm-1">
AVATAR
</div>
<div class="col-sm-11">
<p><%= #p.content %></p>
</div>
<div class="col-sm-12">
LINKS
</div>
</div>
</div>
<% end %>
</div>
<div class="col-xs-3">
<div class="panel panel-default">
<div class="panel-body">
<p>about</p>
</div>
</div>
</div>
</div>
I am using the latest bootstrap sass version 3.3.6 which is included in the gemfile. Is there something wrong with the code or does the latest version of bootstrap mean I need to do something different?
Look at this section:
<div class="col-sm-1">
AVATAR
</div>
<div class="col-sm-11">
<p><%= #p.content %></p>
</div>
<div class="col-sm-12">
LINKS
</div>
The first issue is the text "AVATAR" is wider than 1 bootstrap column, so it's extending out of your container. using col-sm-2/col-sm-10 may fix the issue.
Second, column sizes should add up to 12 columns per row. Here you have a col-sm-1, col-sm-11, and col-sm-12 all in the same row.

Showing Unnecessary border in panel in MVC with Bootstrap

I want to design two panels in same line, its work but showing unnecessary border,
Here is xyz.cshtml code with Bootstrap,
<form class="form-horizontal" role="form">
<div class="panel panel-primary col-md-4">
<div class="panel-heading">Add Members</div>
<div class="panel-body">
<button id="btnAddMem" type="button" class="btn btn-primary" onclick="">ADD</button>
</div>
</div>
<div class="col-md-1">
</div>
<div class="panel panel-primary col-md-4">
<div class="panel-heading">Add Others</div>
<div class="panel-body">
<button id="btnAddOther" type="button" class="btn btn-primary" onclick="">ADD</button>
</div>
</div>
</form>
And output looks like this image,
Any help would be appreciated.
Hello Try this code,
<form class="form-horizontal" role="form">
<div class='col-md-4'>
<div class="panel panel-primary">
...
</div>
</div>
<div class="col-md-1">
</div>
<div class='col-md-4'>
<div class="panel panel-primary">
...
</div>
</div>
</form>
you have added col-md-4 with panel.it will put padding so thats why it will add extra border in your output.
So I have remove it from panel div and added as parent.

Partial Views in another Controllers View MVC5

Im new to using partial views in mvc and for some reason could not get this working
Notes.cshtml
#model IEnumerable<SI2.Models.DashboardNote>
#foreach (var item in Model)
{
<div class="col-lg-12">
<div class="well">
<p>#Html.DisplayFor(modelItem => item.Information)</p><br />
<p>#Html.DisplayFor(modelItem => item.DateCreate)</p>
</div>
</div>
}
This is where I'm trying to call the partial view in another controllers view
Home/Index.cshtml
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fc-agenda-view"></i> Notes</div>
<div class="panel-body">
#Html.Partial("~/Views/DashboardNotes/Notes.cshtml")
</div>
</div>
</div>
</div>
Notes controller
public ActionResult Notes()
{
return View(db.DashboardNotes.ToList());
}
Every time I try calling Notes.cshtml as a partial view I receive a System.NullReferenceException with "Object reference not set to an instance of an object" but if I run the view normally it runs perfectly. There is no relation between the two models of the controllers either.
Thanks for any help:)
The code below will render your partial with no notes, hence the null reference, because you have a foreach for null notes.
#Html.Partial("~/Views/DashboardNotes/Notes.cshtml")
There is no mechanism in Html.Partial that triggers a call to the server. You would have to do some type of ajax call in your partial to get notes if you load it in the manner you are now. The easiest way to go about this is to return the Notes in your parent view or page and pass in the model to your partial, see below:
#model MainViewWithNotes
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fc-agenda-view"></i> Notes</div>
<div class="panel-body">
#Html.Partial("~/Views/DashboardNotes/Notes.cshtml",MainViewWithNotes.Notes)
</div>
</div>
</div>
</div>

Resources