|
Hi ,
Need to get the query string with values on button click with or with out using jquery .
like if my url is like this:
http://localhost:56121/Reports/ProjectScorecardByFilter?id=3" , here want to change the id value to 4 then click on button . In the controller method need to get the value of id as 4 .
|
|
|
|
|
Use the @Url.Action[^] method.
Using a hyperlink:
<a href="@Url.Action("ProjectScorecardByFilter", "Reports", new { id = 3 })">Link</a>
Using a form:
<form method="get" action="@Url.Action("ProjectScorecardByFilter", "Reports")">
<input type="hidden" name="id" value="3" />
<button type="submit">Button...</button>
</form>
Using jQuery:
<button data-link="@Url.Action("ProjectScorecardByFilter", "Reports", new { id = 3 })">JS Button...</button>
<script>
$(function(){
$(document).on("click", "button[data-link]", function(){
var href = this.getAttribute("data-link");
location.assign(href);
});
});
</script>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have an issue with my ASP.NET MVC4 application when I publish it to Azure. The roleManager part is not working and the application returns an error when it reaches to this code in my view:
bool isAdmin = User.IsInRole("admin");
And the error is the following:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5771923
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +507
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
System.Data.SqlClient.SqlConnection.Open() +96
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +75
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +125
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +29
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +386
Interestingly in my local environment, it works fine, and it happens only in Azure.
For publishing to Azure I reconfigured the following properties in my web.config file as well, BUT I am still suspicious if I am missing some configuration somewhere else, since other parts of the application work fine such as login and registration:
Connection String:
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Portal.mdf;Initial Catalog=aspnet-Portal;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString="Data Source=tcp:***,1433;Initial Catalog=***;Persist Security Info=False;User ID=***;Password=***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />
</connectionStrings>
And my Entity Framework configuration:
<entityFramework>
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">-->
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<!--<parameter value="mssqllocaldb" />-->
<parameter value="Data Source=Data Source=***,1433;Initial Catalog=***;Persist Security Info=False;User ID=***;Password=***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
I Was wondering, if there is any other configuration which I need to modify for RoleManager in order to work in Azure?
Thank you for your time and consideration.
|
|
|
|
|
The error message was very descriptive and quite straight forward? It can't connect to SQL Express on the server using the connection string given. If SQL Express is not installed then no configuration or code changes are going to resolve that.
|
|
|
|
|
give me a latest project definition for last 1 year project..
|
|
|
|
|
Sorry, this site is not here to do your work.
|
|
|
|
|
Make a project that can read minds.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi,
I have an ASP.Net MVC Application in which I am using Web Api for Business Logic, I have completed the first page, when I click a button on the first page I need to go to the second page, here I have doubt, should I call the .cshtml, or .html or Controller Get should I call to load the second page or should I add all the components to the same old page with jQuery scripting (I mean single page).
Which is better approach please let me know I am using the ASP.Net MVC, Web Api and jQuery. If I have to call the MVC Controller (not the Api Controller) using the button click then how should I call it using jQuery? Any code snippet, a link or even suggestion would be very helpful.
I am new to the MVC development - thanks in advance my friends.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
The answer all depends on your specific requirements. Usually you have a form that submits to an action on the same controller and that action will do validation and processing and if it is successful it redirects you to the second page by returning a RedirectToAction. You always redirect or link to actions on controllers, never views.
[HttpGet]
public ActionResult PageOne()
{
MyModel model = new MyModel();
return View(model);
}
[HttpPost]
public ActionResult PageOne(MyModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
return RedirectToAction("PageTwo");
}
[HttpGet]
public ActionResult PageTwo()
{
return View();
}
I suggest you get a book on MVC or at least go through some basic tutorials (google for "MVC Music Store") as all these basic topics will be covered.
|
|
|
|
|
How can I call the MVC Controller using jQuery? and one more thing is, can't I call the cshtml page directly using jQuery, because I want to avoid one extra call from cshtml to MVC then MVC to Web Api, instead of that I want to directly call cshtml from button click, that cshtml calls the Web Api directly?
Means I want to avoid MVC Controls calls, instead I want to call the cshtml and then Web Api directly? Am I supposed to do that? If I can can you please give me a small script or some suggestion or Link.
If I am not supposed to call Web Api directly from cshtml then please let me know then please help to call the MVC action method from the button click of the other cshtml page using jQuery.
Thanks a lot my friend.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
A view or .cshtml page won't render without a controller action result, thus MVC.
Yes, you can call a controller action using JQuery. I have a controller called Ajax in which I have JsonResults instead of ActionResults.
I call the JsonResult using $Ajax and send it a model but using primitives, and just return a model "return Json(modelName);"
If it ain't broke don't fix it
|
|
|
|
|
There are various examples of calling controller actions via jQuery here
Useful Way to Call Controller Actions From HTML Using jQuery[^]
I don't really understand what you mean by call the cshtml and then webapi. The reason you can't call cshtml pages directly is because they are just templates, they don't contain all the information you need to render html. Let's say this is in my view
<p>Hello @Model.FirstName</p>
If I were to navigate to that view directly what would appear on the screen? The reason we call actions and not views is because actions combine all available inputs (from the Request, the Session, Databases etc) with the template held in the view to output valid HTML.
You can call a WebAPI directly from a view as long as it's via javascript. You *can* put server-side code in a view to call an API but you shouldn't, it breaks the rules of MVC. So put javascript code in Views if you must, but the only server code should be what is needed to show data from the model, eg a for loop like
@foreach(SearchResult r in Model.Results)
{
<p>@r.Name</p>
}
|
|
|
|
|
Hi,
Yes I did it but still the new page is not rendering.
My default page (that's first page of the application) is: http://localhost:55429/BSCSecurityAddressBookWeb/Employee, means Employee.cshtml is loading, but when I clicked on the button to load a different Page, it goes into the Controller (MultiJobChange) and its View page and then it goes the Partial Page but stays with the same Old page content (ie Employee.cshtml), why is it not rendering the new page (MultiJobChange.cshtml) that it is supposed to when I called as below:
$("#btnMultiJobChange").click(function (event) {
$.get("http://localhost:55429/BSCSecurityAddressBookWeb/MultiJobChange/", null, function (data) {
//alert(data);
});
Any help would be very helpful thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Maybe because you're not doing anything with the response.
If you uncomment the alert(data); line, do you see the HTML from the MultiJobChange page in a messagebox?
You'll need to do something with the response in the callback. Or, you could try using $.load()[^] instead.
Of course, if you just want to navigate to another page, rather than creating a Single Page Application, there are much easier ways to do it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes I am seeing the Page html in string format if I uncomment the alert, but how to to render it I am not able to understand,
And another thing is I am using .load() method but still its not able to load the new Page still it stays on the same Old page, but .load is not even going into the Action method even, at least the Get method was getting into the Action method.
please help me my friend, any help would be much appreciated - thanks in advance buddy
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 27-Jun-17 19:51pm.
|
|
|
|
|
$.get is for when you want to download the html of that url and do something with it in your code, it won't show that page in the browser or navigate to it. If MultiJobChange is a partial view you need to inject the html into the page somewhere.
public class MultiJobChangeController : Controller
{
public ActionResult Index()
{
return PartialView("~/Views/MultiJobChange/_Index.cshtml");
}
}
<div id="target"></div>
<script>
$(document).ready(function () {
$.get("@Url.Action("Index", "MultiJobChange")", function (data) {
$("#target").html(data);
});
});
</script>
or you can use load if you only want to load the html into the div
$(document).ready(function () {
$("#target").load("@Url.Action("Index", "MultiJobChange")");
});
|
|
|
|
|
OK Got it there nothing like Response.Redirect or Transfer in html only thing is I need to inject it. Its old WebFarms model man, sorry my friend and thank you very much too.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Ok, what you want is window.location.href
window.location.href = '@Url.Action("Index", "MultiJobChange")';
|
|
|
|
|
Hi,
If its not a partial View, but View itself, can I use it as well
public class MultiJobChangeController : Controller
{
// GET: MultiJobChange
public ActionResult Index()
{
return PartialView("~/Views/MultiJobChange/Index.cshtml");
}
}
Instead of
public class MultiJobChangeController : Controller
{
// GET: MultiJobChange
public ActionResult Index()
{
return PartialView("~/Views/MultiJobChange/_Index.cshtml");
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi all,
I am getting the following error when I run my Web Application, the error started coming after I got new laptop from my Organization and I moved the code from the Old machine to new machine. I tried to check in the Log file that it mentions but there is no log files created. Any help could be very helpful, thanks in advance.
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information:
Module IIS Web Core
Notification: Unknown
Handler: Not yet determined
Error Code: 0x80070003
Config Error: Cannot read configuration file
Config File: \\?\C:\Users\aaleem01\Desktop\Angular2Apps\BSCSecurityAddressBookWeb\BSCSecurityAddressBookWeb\web.config
Requested URL: http://localhost:55429/BSCSecurityAddressBookWeb/Employee
Physical Path:
Logon Method: Not yet determined
Logon User: Not yet determined
Request Tracing Directory C:\Users\aaleem01\Documents\IISExpress\TraceLogFiles\
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
"Config Error: Cannot read configuration file
Config File: \\?\C:\Users\aaleem01\Desktop\Angular2Apps\BSCSecurityAddressBookWeb\BSCSecurityAddressBookWeb\web.config"
Isn't that quite explicit? Does that file exist? Can it be read by your site? If you have copied those files from another machine there could be security issues on the files.
|
|
|
|
|
The file doesn't exist there, because of the Project moved from different location, then there is another problem, how can I change this, I am using default IIS Express, I didn't create an Explicit Virtual Directory in the IIS but clicked on the Create Virtual Directory, it says directory is created successfully. But I am not understanding why is it still looking for the Web config in the older folder.
Any help would be lot graceful thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Most likely, your application pool is running as a user which doesn't have read permissions to the folder. That's quite common with paths stored within your user profile.
You need to change the NTFS permissions on the folder to grant read access to the IIS_WPG group.
File and Folder Permissions[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a form called "get started" that's on about 10 pages wrapped in form tags on views.
Instead of writing 10 post action results that are the same, I'd like to consolidate them into 1 called "getStarted".
I remember seeing or stumbling upon a how to months ago, but now I can't find it using search.
What I've tried:
So I'm experimenting here, tried the ActionResult but needed a view page for it to work. I haven't made a view yet.
Tried a controller action that is void, but it says page not found after posting. The post actually works and sends the emails and so forth. but I can't do a redirect because I have to action result as a return value.
Any other ideas out there?
If it ain't broke don't fix it
|
|
|
|
|
jkirkerx wrote: I can't do a redirect because I have to action result as a return value
The RedirectResult class[^] is an ActionResult which redirects the response to another URL.
The Controller base class defines several helper methods you can use to redirect the response:
For example:
public ActionResult GetStarted(YourViewModel data)
{
...
return RedirectToAction("Index", "Home");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|