Share tech news, updates, or what's on your mind.

Sign up to Post

I have mvc project with one layout cshtml with some js codes. My goal is to take the parameter (viewbag) value to js file on layout.cshtml.
I try the codes below and "test" does not shown any value when I open the browser >> view source

Do you know how to fix it?

Thanks,


layout.cshtml
<script>

  var test = @ViewBag.showMe
  var locations =
                    [
                 test
                     [locationData('listings-single-page.html', 'http://localhost:29792/images/listing-item-01.jpg', "Tom's Restaurant", '964 School Street, New York', '3.5', '12'), 40.94401669296697, -74.16938781738281, 1, '<i class="im im-icon-Chef-Hat"></i>'],
                     [locationData('listings-single-page.html', 'http://localhost:29792/images/listing-item-02.jpg', 'Sticky Band', 'Bishop Avenue, New York', '5.0', '23'), 40.77055783505125, -74.26002502441406, 2, '<i class="im im-icon-Electric-Guitar"></i>'],
                     [locationData('listings-single-page.html', 'http://localhost:29792/images/listing-item-03.jpg', 'Hotel Govendor', '778 Country Street, New York', '2.0', '17'), 40.7427837, -73.11445617675781, 3, '<i class="im im-icon-Home-2"></i>'],
                     ];  
</script>


Home
Controller:
  public ActionResult Index()
        {
             ViewBag.showMe = " [locationData('listings-single-page.html', 'http://localhost:29792/images/listing-item-01.jpg', "Tom's Restaurant", '964 School Street, New York', '3.5', '12'), 40.94401669296697, …
0
Making Bulk Changes to Active Directory
LVL 8
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

We have an MVC app with a significant amount of javascript code.  We have found a number of our users' browsers are not refreshing Javascript files when they change and are updated on our IIS server.  We have needed to CTRL+R to force a refresh on these browsers.  

How can we address this?
0
In one of the module of our project there are multiple related objects. Here are few of them and the relationships
  • Project
  • Discussions (Related to project. A project must have at least one discussion, 1-M relation)
  • Surveys (Each discussion can have multiple Surveys. Surveys can be added later on, 0-M relation)
  • Questions (Surveys can have questions One survey must have at least one question, 1-M relation)
  • Expected Attendees (A project can have expected attendees, 0-M relation)
There are some other objects as well related to this scenario which I did not included here. In the time of creating a new project entire data needs to be saved in one go. Later on user may add other elements (discussion, surveys etc.) in an existing record.

In Data layer and business layer I created classes for each and every objects (Project, Discussion, Surveys, Question and Attendee). Since in the time of creating a new project few of actions (Survay save, Expected Attendee save etc.) are optional so we are thinking of Decorator pattern to save a project.

Now I have two questions

Should we implement decorator pattern? Or is there any other pattern which address this situation better?
We have to implement the patter in business logic layer. In that case how can I implement transaction? This is a key problem when we are trying to implement any design pattern.
0
I have mvc app that using bundle to generate CDN. Everything in localhost / development environment is working fine.
But when I publish to azure environment and debug using firewall. it alerts all CDN is missing.

Can you tech me what I need to do to avoid this issue occurred...?

Thanks

public class BundleConfig
    {
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            //bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
            //            "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      //"~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }
    }

Open in new window

0
Below codes working but for some reasons it supposes to return 6 records from the ms sql database.but it ends up return 1 record only.
Can you help me to fix it?

Thanks
public ActionResult Index()
        {
return View(EventFleetList());
}
public List<Domain.Fleet> EventFleetList()
        {
            Domain.Fleet f = new Domain.Fleet();
            List<Domain.Fleet> fleetList = null;
            using (SqlConnection connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand("",connection))
            {
                connection.Open();
                command.CommandText = "SELECT * FROM Fleet";
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string id= reader["FleetID"].ToString();
                        fleetList = new List<Domain.Fleet>()
                        {
                                new Domain.Fleet
                                {
                                    id =1,
                                    make = id + " Make",
                                    model = id + " Model"
                                },                                
                        };
                    }
                }
             }
            return fleetList;
        }             



//mvc razor
@model List<Domain.Fleet>  

Open in new window

0
We have a cloud web application developed in .net MVC c#.now I'm starting​ integrate with sage 50 desktop application. Sage 50 provide an SDK for integration. We have to pass data like create invoice,from my web application. So how to do this process? Which is the best solution? Which technology we use here? Web service and things are recommend from sage support team.but how to use this?

Please advise for this,access desktop application from web.
0
I have added areas to my asp.net MVC application, and I have created models inside the area I have created, I'm trying to add the model to the public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, so I can create a migration and update database to get that table added to my DB. but its not recognized. which is the right way of adding models that are located in areas to have them created in the database?
Thanks

PS Im using the code first approach.
0
I am developing a C# .net MVC page to allow users to make some selection, query data and display the data with paging function.
I use a partial view for the data display but fail to maintain the main view and the data after click on different page.

Please advise me, have attached the code as below (Index.cshtml, SearchController.cs, WebGrids.cshtml)

Index.cshtml
______________

@model DLTWeb.Models.SearchModel

@{
    ViewBag.Title = "Index";    
}

<header>
    <script src="~/Scripts/jquery-3.0.0.js"></script>
    <script src="~/Scripts/jquery-3.0.0.min.js"></script>
    <script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>  
    <script src="~/Scripts/gridmvc.min.js"> </script>
    <link href="@Url.Content("~/Content/style.css")" rel="stylesheet" type="text/css" />  
    <link href="@Url.Content("~/Content/PagedList.css")" rel="stylesheet" type="text/css" />
</header>

<h2><font color="blue">@Html.Label("lblReport", "DLT Web Report")</font></h2>

<br />

<table>
    <tr>
        <td>Report Name</td>
        <td>@Html.DropDownListFor(m => m.ReportName, (IEnumerable<SelectListItem>)ViewBag.ListReport, "---------------Select Report----------------", new { @id = "ddlReport", @onchange = "javascript:GetFields(this.value);" })</td>        
    </tr>
    <tr>
        <td>Fields Name</td>
        <td>
            <select id="ddlFields" name="ddlFields">
                <option>---Select Fields---</option>
            </select>
        …
0
I have new using mvc, and I have the following sql statement that will loop for 40 records.
how to make the codes reflect on razor?

    public ActionResult Index()
        {
            Domain.Fleet f= new Domain.Fleet
            {
                //SELECT COUNT(FleetInEvent.FleetID)AS totalCountFleet, WebsiteSetting.EventName FROM FleetInEvent INNER JOIN
                //WebsiteSetting ON FleetInEvent.Domain = WebsiteSetting.Domain GROUP BY WebsiteSetting.EventName ORDER BY WebsiteSetting.EventName
                id = 1,
                totalFleetCount = 200
            };
            return View(f);
        }
0
I have been developing with ASP.NET web forms for years and had decided to learn MVC and Entity Framework model as I am becoming irrelevant in skill set. But in discussions with some of my peers they indicated I should start with ASP.NET Core Razor environment. Since I have had limited exposure to both, I need suggestions on where to get started, kind of like a step one learn this, step two learn that. I am kind of at a loss of where to begin as it all looks so foreign to what I am used to.
0
Free Tool: Port Scanner
LVL 12
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I have the codes below
1. RetrieveData is working fine., but now I want to assign class library value in a loop.
Basically, I have wcf call to get the list of name which is exactly same as class library property name - see newretrievedata
Is it possible to do that?

On another side of class library in c#, i already have all of the property/object in class library.


     
  public JsonResult RetrieveData(string ID)
        {
            Domain.Lead l = new Domain.Lead();
            l.firstname = "John";
            l.lastname = "Smith";
            return Json(l, JsonRequestBehavior.AllowGet);
        }

 
        public JsonResult newRetrieveData(string ID)
        {
            Domain.Lead l = new Domain.Lead();


            foreach (KeyValuePair<string, string> i in Helper.DynamicsCRM.GetAllLeadInfoByMetaData3("a51ec467-7255-e811-81153863bb3c4538"))
            {               
                //Response.Write(i.Key + " >> " + i.Value + "<br>"); Key has firstname, and lastname, etc.
            	l.i.Key = i.Value;
            }
            return Json(l, JsonRequestBehavior.AllowGet);
        }

Open in new window

0
I am currently experiencing something strange with one of my routes' responses and haven't been able to find any information elsewhere.

So, let's say I make a call to a route in my controller with JQuery, like this. It's a POST action and I expect JSON data.

// Send the data
            $.ajax({
                type: "POST",
                enctype: 'multipart/form-data', //'application/json',  
                url: "/Claims/Application/SaveCurrentFormData",
                data: data,
                dataType: 'json', // we're expecting back a json
                processData: false,
                contentType: 'application/json',
                cache: false,
                timeout: 600000,
                success: function (result) {                      
                    for (var formCode in result.forms) {
                        var selector = "[data-formcode='" + formCode + "']";
                        $(selector + " [name='TicketDocumentId']").val(result.forms[formCode]);
                    }

                    for (var documentName in result.documents) {
                        var selector = "input[name='" + documentName + "']";
                        $(selector).data("ticketdocumentid", result.documents[documentName]);
                    }

                    resolve(true);
                },
                error: function (e) {
                    // Debug
                    console.log("Error saving form data: ", e.message, e);

        

Open in new window

0
Hello to all I tried an enterprise structure like below:

image

And my models are like so:

public class Course : Entities
    {
      
        public int Credits { get; set; }
 
        public virtual ICollection<Enrollment> Enrollments { get; set; }
      
    }
 
  public enum Grade
    {
        A, B, C, D, F
    }
    public class Enrollment : Entities
    {
      
 
        public int CourseID { get; set; }
        public int StudentID { get; set; }
        public Grade? Grade { get; set; }
 
        [ForeignKey("CourseID")]
        public virtual Course Course { get; set; }
        [ForeignKey("StudentID")]
        public virtual Student Student { get; set; }
        
    }
 
 public class Student: Entities
    {
       
        public string LastName { get; set; }
        public string FirstMidName { get; set; }
        public DateTime EnrollmentDate { get; set; }
 
        public virtual ICollection<Enrollment> Enrollments { get; set; }
        
    }
 
  public class Entities:IEntity
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Key]
        public int ID { get; set; }
        [Required]
        public string Title { get; set; }
    }
 
 public interface IEntity
    {
          int ID { get; set; }
        //string Title { get; set; }
    }

Open in new window


And my context:

 public EFBlogContext()
            : base("Blogst")
        {
        }
        public DbSet<Student> Students { get; set; }
        public DbSet<Enrollment> Enrollments { get; set; }
        public DbSet<Course> Courses { get; set; }
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
         
            
            base.OnModelCreating(modelBuilder);
        }

Open in new window


And here is my up method:


Open in new window

0
Below code is working in web form. But I convert into mvc so I have <select id="htmlList"></select>
so how can i use Helper.DynamicsCRM.GetOptionSetItems("lead", "new_rv_type") binding with "htmlList"?


Web Form
ddlTitle.DataSource = Helper.DynamicsCRM.GetOptionSetItems("lead", "new_rv_type");
ddlTitle.DataBind();
<asp:DropDownList runat="server" ID="ddlTitle" DataTextField="text" DataValueField="value"></asp:DropDownList>
0
i JUST WANT TO know how to consume below api by using c# code behind

https://apidocs.leadsquared.com/create-a-lead/
0
try to publish from mvc app to azure.
even I remove all of the files and folder in obj folder,
this issue still bothering us for each website. It is not codes issue because even we tried to publish empty website. the issue remain  the same.


Copying file bin\System.Web.Mvc.xml to obj\Release\Package\PackageTmp\bin\System.Web.Mvc.xml failed. Could not find file 'bin\System.Web.Mvc.xml'.
0
I have the html form below in index.cshtml
and want to submit them to email using code behind.
I am new on MVC, and can you show me how to do that? I know how to send email in codes, just do not want what is the best practice to carry the data into code behind.

<form class="account-settings-form" id="form">
                        <br /><br />
                        <h5>General Information</h5>
                        <p class="small-paragraph-spacing">By letting us know your name, we can make our support experience much more personal.</p>
                        <div class="row">
                            <div class="col-sm">
                                <div class="form-group">
                                    <label for="first-name" class="col-form-label">First Name:</label>
                                    <input type="text" required class="form-control" id="first-name" placeholder="Your First Name">
                                </div>
                            </div><!-- close .col -->
                            <div class="col-sm">
                                <div class="form-group">
                                    <label for="last-name" class="col-form-label">Last Name:</label>
                                    <input type="text" required class="form-control" id="last-name" placeholder="Your Last Name">
                                </div>
                            </div><!-- close .col -->
                            <div 

Open in new window

0
I'm new to mvc and razor

i have an image showing on first load with no issues (camera1.jpg)

its written in the c# backend and set on the screen with no problem at all (on initial load)

then, when the c# tries to set a different image (camera3.jpg), it doesn't change from image1 to image2
however when i debug its showing the new image  (camera3.jpg) in the variable, but the one on screen is always showing the original (camera1.jpg)

here is the code,and it show the variable with the new image, but it does not update the img
cam
what am i doing wrong?
0
im implementing MVC project and getting errors when using database first. I'm using Entity Framework 5 with .NET version of 4.0. not sure if thats the reason for the rrors

Severity      Code      Description      Project      File      Line      Suppression State
Error      CS0115      'SybaseEntities.OnModelCreating(DbModelBuilder)': no suitable method found to override      BCUW.SybaseConnect      C:\Users\e136341\Desktop\MVC 4\BCUW.SybaseConnect\SybaseConnect.Context.cs      24      Active
Entity-Framework-Error.PNG
0
Turn Raw Data into a Real Career
Turn Raw Data into a Real Career

There’s a growing demand for qualified analysts who can make sense of Big Data. With an MS in Data Analytics, you can become the data mining, management, mapping, and munging expert that today’s leading corporations desperately need.

I have been working with SQLDependency to address a business rule problem. One of my last problems I am encountering is, "How can I see what record got added or updated from using SQLDependency?"

I have an example MVC Project using SingalR to automatically refresh a page but not sure how to see just the changed data.
0
during publish, out of below code one line is gets excluded . it's weird , does anyone else has seen such thing.
public JsonResult GetMethod(ProDetails criteria)
        {
            PResponseApp response = new PResponseApp();
            criteria.UserName = "21927198";  // this line disappears resulting in null value for username
            response = ProDetailsObjBL.GetProTerminal(criteria);
            return Json(response, JsonRequestBehavior.AllowGet);
        }
0
Hello Friends,
I have a chart which i have built using the linq query which is as below
 
public List<DatewiseStockDetailViewModel> getProductSoldByYear(int CompanyId)
{
var userData = (from m in datewise.GetAll()
join s in stock.GetAll()
on m.Stock_Id equals s.Stock_Id
join p in product.GetAll()
on s.ProductId equals p.ProductId
where s.CompanyId == CompanyId && m.IsProductDeducted == true
group new { m, s, p } by new { Convert.ToDateTime(m.CreatedDate.ToString()).Year, p.ProductName, p.ProductId } into g
select new DatewiseStockDetailViewModel
{
productId = Convert.ToInt32(g.Key.ProductId),
productName = g.Key.ProductName,
ProductQuantity = g.Sum(x => x.m.ProductQuantity),
year = g.Key.Year.ToString()
}).Distinct().ToList<DatewiseStockDetailViewModel>();
return userData;
}

Open in new window


This is the current output which i am getting
But i want to write a code by which i am able to use the pivot code in linq to get the output as
ProductName         2016         2017         2018
cedar oil                  NULL        16         34
computer                 NULL         8               1
grain                        NULL   21       NULL
Keyboard                  2           3       NULL
marie                        NULL        26     NULL
Pine Oil                     NULL         4                  5
harabhara kebab      NULL            5               1
 
For this i have written the sql query
 
select *
from(
select pd.ProductName,year(dsm.CreatedDate)as [Year],sum(dsm.ProductQuantity)as ProductQuantity
from dbo.DatewiseStockDetailMaster dsm
left join dbo.StockMaster sm on
dsm.stock_Id=sm.stock_Id
left join dbo.ProductDetails pd
on sm.ProductId=pd.ProductId
where sm.CompanyId=17 and dsm.IsProductDeducted=1
group by year(dsm.CreatedDate),pd.ProductName
)as SourceTable
pivot
(
sum(ProductQuantity)
for [Year]
in([2016],[2017],[2018])
)
as pivotTable

Open in new window


How to convert from sql to linq using pivot
0
When I was developing applications in Microsoft Access, the most usual UI was a form with one or more subforms; for example, customer order with order items. The user usually fills the main form with order details, then adds several order line items one by one.

Now I'm looking into building new applications by MVC in Visual Studio 2015, and in MVC there's no subdataforms. What is the recommended/standard way to present master/detail UI in MVC, to accomplish scenarios like the above?

I'm looking at MVC mostly as RAD tool, so trying to use "from the database" model rather than "from code". The expectation is to build database model of the solution, then have MVC build web application from it, with some minimum manual adjustments.
0
I have the codes below inside of the Controllers in MVC project. This is API project that I tried to learn.
My question is: how can I create end point for Get(int id)? Should I create a VIEW?

My goal is to create end point, and I will have another website project to call the end point so the website can consume the API service.


  public class LeadController : Controller
    {
        [HttpGet]
        public IEnumerable<CrmModels.Lead> Get(int id)
        {
            CrmModels.Lead l = new CrmModels.Lead();
            List<CrmModels.Lead> li = new List<CrmModels.Lead>();
            if (id == 1)
            {
                l.firstName = "John";
                li.Add(l);
            }
            else
            {
                l.firstName = string.Empty;
                li.Add(l);
            }
            return li;
        }
        //Get api/lead details
        [HttpGet]
        public IEnumerable<string> Get()
        {
            //call crm controllers 
            return new string[] { "", "" };
        }
        //create
        [HttpPost]
        public void Post(CrmModels.Lead l)
        {
            //call crm controllers 
        }
        //update
        [HttpPut]
        public void Put(int id)
        {
            //call crm controllers 
        }
        //delete
        [HttpDelete]
        public void Delete(CrmModels.Lead l)
        {
            //call crm controllers 
        }
    }

Open in new window

0
we want to use https://www.espocrm.com/ as our primary CRM. but I just do not know how to create API with them.
They have very limited documentation about that.

And if you know how to create CRUD API with this crm, please help me. and I will be really appreciated your helps.
Currently, I have MVC website and can use jquery/ajax to create json to call. I am very new to do that so if you can show me examples in codes....that will be awesome.
0

.NET MVC

176

Solutions

194

Contributors

Top Experts In
.NET MVC
<
Monthly
>